-->
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: save/update object with lazy components
PostPosted: Tue Aug 03, 2004 2:08 pm 
Newbie

Joined: Fri Jul 16, 2004 6:22 pm
Posts: 17
Can an object with uninitialized lazy collectsions (whose elements are a UserType) be saved without first loading the lazy collection. I have been told this can be done, but I can not get it to work. The code generally looks like this:

Code:
Session lSession = sf.openSession();
List<Persistable> l = lSession.find(*some HQL*);
Persistable obj = l.get(0);
*change something in object, NOT touching lazy collection*
session.saveOrUpdate(obj);


On the last line, when trying to saveOrUpdate(), Hibernate tries to load the lazy collection before saving. I just want it to update the one thing I changed... Can anyone give me some direction here? Any help is appreciated.

Thanks in advnace for all responses.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 2:34 pm 
Beginner
Beginner

Joined: Wed Jun 23, 2004 12:37 pm
Posts: 20
Not sure if this will solve your lazy loading problem, but...

If your Session is still open you don't need to call update (or saveOrUpdate). Either commit the transaction or flush the session (depending on you autocommit setting in the db) will save any changes you made to the object.

If like me you came to Hib' from an EJB 1.1 background you'd expect to have to call some sort of 'update' but Hib' takes care of that if the object is still associated with an open Session.

Cheers,

Nick


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 4:41 pm 
Newbie

Joined: Fri Jul 16, 2004 6:22 pm
Posts: 17
That is true. Although it still tries to load the lazy collections.

Any one have and *ideas* (they don't have to be spot on)? I'm really getting desperate here.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 4:44 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Most likely, you have cascade="save-update" or "all" enabled for this association. There is nothing "lazy" happening, it's just Hibernate looking for any modifications you might have made to the collection elements, because you told it to do so.

I can only repeat that saveOrUpdate() is probably not what you are looking for if you just want to have a SQL UPDATE with your changes. For this, just commit the Transaction (implicitely flushes the Session), close the Session.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 5:26 pm 
Newbie

Joined: Fri Jul 16, 2004 6:22 pm
Posts: 17
When I first read this I thought, "Yes! That's probably it!", but cascade for the collection is set to "none". On update() Hibernate still calls the getter for my uninitialized lazy collection. I do want to use update because my transaction spans multiple method calls, and I only want to commit if everything succeeds?

Should the getter for my collection be called in this situation?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 5:29 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
No, and your next step will be a Hibernate TRACE level log (don't post it here!) that will tell you why Hibernate would think it has to update the associated instances. If you have isolated the lines of log, post all that is mentioned in the red box.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 6:00 pm 
Newbie

Joined: Fri Jul 16, 2004 6:22 pm
Posts: 17
Thanks for your responses.

I've been trying to get the logging going with the JDK 1.4 logging, but am failing so far. Can you tell me or point me to somewhere that demonstrates this? I found this: http://www.hibernate.org/119.html#A15 but it wasn't very helpful.

I tried both:
net.sf.hibernate=TRACE -- this gave an error, it doesn't like TRACE
net.sf.hibernate=FINEST


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 6:01 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
DEBUG will do

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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.