This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line!
See this thread for details.
Win a copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java this week in the Agile and Other Processes forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Hibernate and extra insert

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem with Hibernate (Annotations). Here are my Entities:



This one works just fine. The other one that does not is here:



Now, the problem: before I persist ProblemEntity, I call:



After this code, I try to save my ProblemEntity and then flush the session object (the same session that retrieved e1). Even though e1 is not transient and has a valid ID (I checked it), Hibernate tries to insert both problemEntity and e1 (in this order). What am I doing wrong? (both classes are mapped in hibernate.cfg.xml)
[ May 21, 2008: Message edited by: Marco Tulio Borges ]
 
Ranch Hand
Posts: 265
Hibernate Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marco,

It looks like you need to pick which side of the association is the owner, and on the annotation for the other side, include the mappedBy attribute on the inverse side. This will let the owning side of the association manage the relationship, and tell the inverse side it is not responsible for maintaining that relationship.
 
What's gotten into you? Could it be this tiny ad?
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!