Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JPA Recursive Updates for One-To-Many and Many-To-One Relationships

843830Feb 23 2008 — edited Feb 26 2008
From what I can tell, I may have designed a recursive call and caused a stackoverflow. For example:
1. Purchased items will have a warranty(A).
1. A computer (B) has a one-to-many relationship with warranty (A).
2. A server (C) has a one-to-many relationship with warranty (A).
3. A Peripheral (D) has a one-to-many relationship with warranty (A), computer (B), and server (C).

When I define each relationship within the entity, I place the @ONETOMANY annotation in the owning entity. In the subordinate entity I place the @MANYTOONE annotation.

Here is where it gets a little fuzzy for me. I have tried to follow some good books on EJB 3.0, such as "EJB3 in Action" by Panda, et al. However it lacks clear examples for the scenario I am facing.

What happens when I have a server (C) with many peripherals (D) and each has the same type of warranties (A), such as manufacturer warranty and extended warranty (with some basic info like expiration date, etc)? The EJB Beans gets a request to update C. Updating the single fields and one-to-one relations are straightforward. Now working through the peripherals (D) I am confused. The normal way would be walk through each peripheral and "persist" each item separately because you do not know which has been updated. Action involving new entries would be obvious because each would not have a PK field populated.

While my scenario is easily depicted/created in the database, the implementation of this type of relation is confusing to me in JPA. Could anyone please explain or throw me a link that explains this operation in JPA?

Thank you for taking the time to read my post! I appreciate you taking the time out to assist me.

Russ
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 25 2008
Added on Feb 23 2008
16 comments
1,899 views