-->
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.  [ 8 posts ] 
Author Message
 Post subject: Transient Obj errors on deep relationships on save / update
PostPosted: Wed Feb 11, 2004 4:23 pm 
Newbie

Joined: Wed Feb 11, 2004 4:09 pm
Posts: 3
I have a Parent (Job) that may contain many Children (Sections). Each Section may contain many SubSections. I'm loading an existing Job from one session and am trying to add / save a brand new Section with a new SubSection in a different Session. When trying to save the new SubSection Hibernate throws some exception saying that that SubSection references a transient Section instead of going ahead and saving the Session. The same problem exists when adding a new Job with new Section and SubSection.

I've been abke to duplicate these exeptions when using "all", "all-oprhan-delete", and finally "save-update" for my cascade value. I'm currently using a Set, but I've duplicated this problem using bag as well. I've also tried specifying an unsaved-value as well as implementing Interceptor.isUnsaved() and haven't found anything that works. Switching between session.update(..) and session.saveOrUpdate(..) has made no difference.

Obviously I could iterate over everything to call save / update in the expected order, but is there anyway that I get a deep save / update by saving/updating the parent?

// Logging / Exception Info:

// Section to Add
2004-02-11 11:58:41,383 [DEBUG] - SECTION: SectionDO@d861b7[id=0] // not saved
// Section has a not-null reference to its parent
2004-02-11 11:58:41,383 [DEBUG] - JOB REF: Job@1f7670d[id=1082]

// SubSection to Add
2004-02-11 11:58:41,383 [DEBUG] - SUBSECTION: SubSection@18e95d9[id=0] // not saved
// SubSection has a not-null reference to its parent
2004-02-11 11:58:41,383 [DEBUG] - SECTION REF: SectionDO@10098b[id=0] // not saved

// Exception when cascades equal


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 5:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Do you have that Interceptor attatched? Have you tried doing without, and instead setting unsaved-value=null?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 6:01 pm 
Newbie

Joined: Wed Feb 11, 2004 4:09 pm
Posts: 3
Yes, I've tried using unsaved-value="null" -- no change

And Yes, MyInterceptor is connected:

public static final Session currentSession() throws HibernateException {
Session s = (Session) session.get();
if (s == null) {
s = sessionFactory.openSession(new MyInterceptor());
session.set(s);
}
return s;
}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 13, 2004 10:08 am 
Newbie

Joined: Sat Mar 13, 2004 9:46 am
Posts: 10
Has this issue already been solved?! I have the same problem and I was wondering how you solved this problem?

dee3lmo!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 13, 2004 10:12 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Have you tried session.lock(object) before saving?

Anthony


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 13, 2004 10:55 am 
Newbie

Joined: Sat Mar 13, 2004 9:46 am
Posts: 10
With session.lock(object) :

Exception in thread "main" net.sf.hibernate.HibernateException: cannot lock an unsaved transient instance


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 13, 2004 11:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
Has this issue already been solved?


I very much doubt that there is any "issue". You have a bug in your code. You will need to provide said code if you want any help fixing the bug.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 15, 2004 11:18 am 
Newbie

Joined: Wed Feb 11, 2004 4:09 pm
Posts: 3
Yes, I found / resolved my problem. My classes used bi-directional relationships. The problem was that one of my objects did not reference the same instance ("==" comparison failure) of the other object being saved. So, all my properites were set -- just not referenced correctly. I fully expected it to be my fault. I just hate that I didn't find this sooner.


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