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—
|