-->
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.  [ 3 posts ] 
Author Message
 Post subject: Detached object w/ lazy collections
PostPosted: Sat Mar 26, 2005 2:05 am 
Regular
Regular

Joined: Thu Apr 15, 2004 1:12 pm
Posts: 55
Hibernate version: 2.1

Hi,

I need some help with detached objects and lazy collections. The scenario is that an HTML form is built in the Web tier from a collection in a persistent object. When the form is submitted, changes are made to the (now detached) object; in particular, changes may be made to the collection (removal of elements and/or additions of new elements). These (Set) operations are throwing LazyInitializationException all over the place.

If it were as simple as just that, I'd just call Hibernate.initialize() on the collection before passing it up to the web tier. Unfortunately, I'm not sure it's as simple as just that, because this collection is the interse end of a many-to-many association, so to persist the change I need to make the corresponding change to the corresponding non-inverse collections and persist their owning objects. That collection is rather large, so it's important that it be lazy; and I don't know in advance which of those non-inverse collections will be the ones needing to be changed.

I just picked up my copy of the HiA book (thanks Christian and Gavin!) and I'm enjoying going through it. I've done some Hibernate before, but it's always beeen "in the heat of battle", and it's nice to be able to spiral through this once more and fill in some gaps in my knowledge. Anyway, I looked through the chapter on building layered applications (Chapter 8, I think), and was hoping to find some tips on getting lazy collections to work in the "session per HTTP transaction" model, but I came up empty-handed!

This is a design and code-base I "inherited" from someone else, and I don't have the luxury right now of converting it to the "long Hibernate session" model.

As a point of information — I'm using Cocoon (not that that's relevant, but somebody might find it interesting).

Anyway, and tips/techniques/gotchas much appreciated...
thx,
—mark—


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 26, 2005 7:02 am 
Regular
Regular

Joined: Thu Dec 11, 2003 4:14 pm
Posts: 86
Location: Hibernate 3 + annotations, Oracle 9i, PostgreSQL 8.0, Java 1.5.0
For sure you know you have to use session.update(pojo) to get a detached object into the current session?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 28, 2005 2:49 pm 
Regular
Regular

Joined: Thu Apr 15, 2004 1:12 pm
Posts: 55
Hey thanks imario!

It turns out, the session.update() was being called after the code that tries to manipulate the object graph.

Now I have another problem, but I'll start a separate thread for that...
—ml—


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