-->
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.  [ 2 posts ] 
Author Message
 Post subject: Pls help with the TransientObjectException
PostPosted: Mon Jan 07, 2008 8:34 pm 
Newbie

Joined: Thu Jan 03, 2008 7:21 pm
Posts: 15
Hi,

I have two classes with one to many relationship, let's say Parent and Child.

I used the following method to load the Parent from DB

Parent parent = getHibernateTemplate.get(Parent.class, parentId);

Then I created a new Child and set its parent property

child.setParent(parent);

Finally, I tried to save the child with the following code:

getHibernateTemplate.merge(child);

At this point I got the following exception:
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: Parent

The thing that I couldn't understand is I just loaded the parent obj from DB, how could it become transient?

I can make that exception disappear by setting the @ManyToOne(cascade=CascadeType.ALL), but that ends up with duplicate Parent objects being saved into the DB.

Thanks for any help.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 08, 2008 12:48 am 
Newbie

Joined: Thu Jan 03, 2008 7:21 pm
Posts: 15
The Exception disappeared after I removed the @Version field.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.