gavin wrote:
Well, you can do it using session.lock(). But this is absolutely the wrong way to do it. If you use a query with a FETCH of the objects you need, they will already be initialized when you get to the view.
what if the total amount of information in the result set is so large that you cannot realistically pull it all back at once? ie, a result set of 2000 records, paging at 20 records a pop and each record has 3 collections each that need to be loaded for display. the sheer amount of data that needs to come back can overwhelm the initial query execution -- whether you use FETCH or Hibernate.initialize().
as for session.lock(), i did see this in the hibernate 2.1b2 roadmap:
support for passing a transient object to Session.lock() (DONE)
(*) to allow initialization of associations, eg.
if ( !Hibernate.isInitialized( foo.getBars()) ) session.lock(foo, LockMode.NONE);
Iterator iter = foo.getBars().iterator();
based on what you said, however, doing this is absolutely the wrong way to do it. if that is the case, was this functionality in 2.1b2 put here for some other reason?
thanks!
james