It's not a secret anymore!*
The moose likes Object Relational Mapping and the fly likes @OneToMany, detached adding an object to the list -> org.hibernate.TransientObjectException 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 "@OneToMany, detached adding an object to the list -> org.hibernate.TransientObjectException" Watch "@OneToMany, detached adding an object to the list -> org.hibernate.TransientObjectException" New topic
Author

@OneToMany, detached adding an object to the list -> org.hibernate.TransientObjectException

Markus Schmider
Ranch Hand

Joined: Feb 25, 2007
Posts: 86
I have a class A which has a .



I use it in an web application, so A becomes detached. The User can add B instances to A.
When I try to merge A which reference a new B instance I get

Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: B

Is this the expected behavior for JPA 2.0?

Do I have to write code to save B before saving A or this there some way to automate this with the right mapping annotations?

Thanks,

Hans
Markus Schmider
Ranch Hand

Joined: Feb 25, 2007
Posts: 86
Ok I have found out for myself:

You have to add a CascadeType



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: @OneToMany, detached adding an object to the list -> org.hibernate.TransientObjectException
 
Similar Threads
Getting a 'TransientObjectException' error message
TransientObjectException while fetching data.
Problems using Hibernate Criteria API
Hibernate logging in log4j
please solve this prob