• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

What is the sequence of persisting for a bidirectional associations?

Ranch Hand
Posts: 558
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.



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.
    Bookmark Topic Watch Topic
  • New Topic