• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Saving parent, children and grandchildren in Hibernate

 
Saket Barve
Ranch Hand
Posts: 229
  • 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
 
Scott Johnson
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: 229
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic