This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Saving parent, children and grandchildren in Hibernate  RSS feed

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

My datastructure is something like this: Single Page contains many samples and each sample contains many sample items.

I am trying to insert all the screen data at a go, through a single call of session.save( Page )

For this, after creating a new page, adding samples and sample items to each of the samples on the UI, I convert the client VO to hibernate model VO and set the data as required.

When I try to save, I get org.hibernate.NonUniqueObjectException. I don't know the cause of this - when creating hibernate model object I do a "new" every time. Also, I have set the cascade property to delete-all-orphan as required.

I'd appreciate any feedback at the earliest.

Thanks,
Saket
 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saket,

From the javadoc:

This exception is thrown when an operation would break session-scoped identity. This occurs if the user tries to associate two different instances of the same Java class with a particular identifier, in the scope of a single Session.



For me to help you beyond that you'll need to post the relevant code (preferably a concise example).
 
Saket Barve
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Scott.

The problem was that I was not setting the generator property appropriately.

Modifying



to



seemed to do the trick. The MEAS_SAMPLE_SEQ is a sequence for the concerned table to generate PK's.

I believe the NotUniqueObjectException was due to the fact that the (default) ID for a new item was being used for all the inserts.

Saket
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!