my dog learned polymorphism
The moose likes Object Relational Mapping and the fly likes Getting a 'TransientObjectException' error message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Getting a Watch "Getting a New topic

Getting a 'TransientObjectException' error message

Vance Arocho

Joined: Sep 29, 2011
Posts: 6
I'm getting a 'TransientObjectException' error message when I try to update a record from the 'reference' table in my database:

org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: org....domain.Author
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(
at org.hibernate.type.EntityType.getIdentifier(
at org.hibernate.type.EntityType.replace(
at org.hibernate.type.TypeFactory.replace(
at org.hibernate.event.def.DefaultMergeEventListener.copyValues(
at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(
at org.hibernate.impl.SessionImpl.fireMerge(
at org.hibernate.impl.SessionImpl.merge(
at org.hibernate.impl.SessionImpl.merge(
at org.springframework.orm.hibernate3.HibernateTemplate$23.doInHibernate(

Here's part of the 'Reference' class:

and here's part of the 'Author' class:

Here's the code to update the specified 'Reference' object:


Do I need to call the 'getPrimaryauthor()' method on the 'Reference' object first, and then save that 'Author' object prior to calling the 'merge' method ?
Vance Arocho

Joined: Sep 29, 2011
Posts: 6
I ended up getting the 'Author' object from the 'Reference' object and doing a lookup to see if the specified author already exists. If not, then I call the 'HibernateTemplate' object's 'save' method, passing it the 'Author' object. In either case, I set the 'Author' object on the 'Reference' object prior to calling the 'merge' method on the 'HibernateTemplate' object, passing in the 'Reference' object.
Vijitha Kumara

Joined: Mar 24, 2008
Posts: 3900

You may have detached the reference to the Author instance before this? It may depends on how you manipulate these entities after being retrieved anyway...

[How to ask questions] [Twitter]
I agree. Here's the link:
subject: Getting a 'TransientObjectException' error message
jQuery in Action, 3rd edition