File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting a 'TransientObjectException' error message

 
Vance Arocho
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic