Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Getting a Watch "Getting a New topic
Author

Getting a 'TransientObjectException' error message

Vance Arocho
Greenhorn

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(ForeignKeys.java:219)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:397)
at org.hibernate.type.EntityType.replace(EntityType.java:253)
at org.hibernate.type.TypeFactory.replace(TypeFactory.java:482)
at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:340)
at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:267)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:120)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665)
at org.springframework.orm.hibernate3.HibernateTemplate$23.doInHibernate(HibernateTemplate.java:817)

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:

hibernateTemplateObj.merge(referenceObj);

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
Greenhorn

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
Bartender

Joined: Mar 24, 2008
Posts: 3775

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...


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting a 'TransientObjectException' error message
 
Similar Threads
TransientObjectException
org hibernate PropertyAccessException
TransientObjectException while fetching data.
TransientObjectException of hibernate
TransientObjectException in Hibernate