-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: org.hibernate.TransientObjectException
PostPosted: Mon May 26, 2008 7:33 am 
Newbie

Joined: Fri Apr 18, 2008 1:07 am
Posts: 14
Location: Pakistan
Hi All!

Please help me. I am facing the following problem.

Quote:
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: bloodbank.persistence.Blood
org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:216)
org.hibernate.type.EntityType.getIdentifier(EntityType.java:99)
org.hibernate.type.EntityType.isDirty(EntityType.java:216)
org.hibernate.type.TypeFactory.findDirty(TypeFactory.java:412)
org.hibernate.persister.entity.BasicEntityPersister.findDirty(BasicEntityPersister.java:2538)
org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:344)
org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:108)
org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:190)
org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:70)
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
bloodbank.persistence.UserDAO.save(UserDAO.java:44)
bloodbank.action.SaveUserAction.execute(SaveUserAction.java:41)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

_________________
Muhammad Kashif Nazar
Software Engineer


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 26, 2008 9:27 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
this is because your association object hasn't already saved. Please post the code


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 26, 2008 12:50 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Yes, my guess is that both sides of the relationship have not been saved. Pass both instances to the EntityManater/Session, and you will likely see this error go away.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 26, 2008 2:51 pm 
Newbie

Joined: Fri Apr 18, 2008 1:07 am
Posts: 14
Location: Pakistan
Thanks for your reply!

How can I do it?
This is what I am trying...

This is my user class that has an object of Blood Type, with its proper getters and setters.


Code:
public class User{
   private String userName;
   private String password;
   private String firstName;
   private String lastName;
        private Blood blood=new Blood();

}


I have DAOs for User and Blood, namely UserDAO and BloodDAO.

At the time of execution, all the properties of the User object are filled.
This line generates the exception.

Code:
new UserDAO().save(saveUserForm);


Please help me! I would be grateful to you

_________________
Muhammad Kashif Nazar
Software Engineer


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 26, 2008 9:01 pm 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
just load the Blood from DB which has unique identifier.

For example :

Code:
...
Blood blood = (Blood) session.load(Blood.class, 1L);
User user = new User();
....
user.setBlood(blood);
new UserDAO().save(user);


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 26, 2008 9:02 pm 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
just load the Blood from DB which has unique identifier.

For example :

Code:
...
Blood blood = (Blood) session.load(Blood.class, 1L);
User user = new User();
....
user.setBlood(blood);
new UserDAO().save(user);


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 27, 2008 1:49 am 
Newbie

Joined: Fri Apr 18, 2008 1:07 am
Posts: 14
Location: Pakistan
Thanks Slau!

The problem here is that I have to save the Blood information encapsulated in the user object. I don't have to read it from database, I just have to save the user that has blood information in it.

_________________
Muhammad Kashif Nazar
Software Engineer


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.