File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes What is the sequence of persisting for a bidirectional associations? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "What is the sequence of persisting for a bidirectional associations?" Watch "What is the sequence of persisting for a bidirectional associations?" New topic
Author

What is the sequence of persisting for a bidirectional associations?

Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 516
    
    2

Hello All,

Is there any way to be followed when persisting relations which are bi directional? For example, I have a domain model where Persons and Events are related in a Many to Many bidirectional fashion.

A person can attend many events and a event can have a multiple persons registered and navigation from both sides is permitted.

Person.java



Event.java


In my client, I have created multiple events and persons as follows


Now my question here is, do I need to establish the relation ship after saving each of the objects or can the association be established first and persist the objects and associations.

If I can estalish the references first and then the persist, my code looks like


I have some persons who are not interested in any events and some events where nobody comes. In such a kind of requirement, how should I be modelling my pojos and configuration and how do I persist them effectively. Which should be persisted first, objects or associations? Do I need to setup the assocation between Person to Event first or Event to Person first. Is there any thumbrule, I should be aware of.


Regards
KumarRaja

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the sequence of persisting for a bidirectional associations?
 
Similar Threads
How to persist objects having circular references using Hibernate
Arrays.asLIit() casting exception (JDK 1.4)
inverse=true in many-to-many doubt
Having trouble in understanding bi directional relationships
How can we determine whether an object's reference variable is null or not?