-->
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.  [ 5 posts ] 
Author Message
 Post subject: TransientObjectException when save
PostPosted: Sat Apr 28, 2007 11:23 pm 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
I have ManyToMany relation between Student and Course.

class Student {

@ManyToMany(....)
public List<Course> getCourses() { ...}
public void setCourses(List<Course> courses) {...}

}

After modifying the course collection of a student, and then update the student, I got the following exception:

javax.ejb.EJBTransactionRolledbackException: java.lang.IllegalStateException: org.hibernate.
TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: pacakge.Course

The student and courses have already been persisted in database before updating the student. What is the possible reasons for the error?

Thanks! Dave


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 29, 2007 8:43 am 
Senior
Senior

Joined: Sat Apr 21, 2007 11:01 pm
Posts: 144
Can you post some more code like what your doing before the error occurs, do you have a JUnit test to replicate it? Also the full stack trace would be nice...

_________________
Everytime you get an answer to your question without giving credit; god kills a kitten. :(


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 30, 2007 1:19 am 
Newbie

Joined: Thu Apr 19, 2007 1:46 am
Posts: 10
Hi ,

What i can think of without the code is that maybe you missed the cascade option in the student class.


Try this with your collection
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 30, 2007 11:11 pm 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
Thanks!
I am using JBoss 4.0.5GA, The CascadeType does not have SAVE_UPDATE or DELETE_ORPHAN.

If I retrieve a list of courses from database and assign them to a student , and then save(merge) the student, all in one transaction, it works fine, no errors.

The issue occurs when I work on detached entities, because of the nature of web application.

Transaction 1: get the student from database
Transaction 2: get all available courses from database
Transaction 3: let user select a number of courses (no db operation)
student.setCourses(selectedCourses);
Transaction 4: merge the student. --- error occurs.
em.merge(student)


Thanks for ideas.

gurpreet wrote:
Hi ,

What i can think of without the code is that maybe you missed the cascade option in the student class.


Try this with your collection
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 30, 2007 11:20 pm 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
It is @ManyToMany relation. Changing students should not change courses. MERGE/SAVE_UPDATE cascade will change courses. correct? Thanks.

gurpreet wrote:
Hi ,

What i can think of without the code is that maybe you missed the cascade option in the student class.


Try this with your collection
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})


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