-->
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.  [ 1 post ] 
Author Message
 Post subject: Reattachment initializes proxies (and all that)
PostPosted: Thu Jan 03, 2008 4:22 am 
Newbie

Joined: Wed Jan 02, 2008 2:55 pm
Posts: 1
Location: Berlin, Germany
Hi all,

Just curious about the following observation. Like a lot of other people I have a web application that lets its users navigate and edit a huge object graph across multiple HTTP requests. I use OpenSessionInView and lazy-loading, I do not persist anything back to the database until the user clicks on a save button. Until then I reattach the object graph using LockMode.NONE in each request cycle.

I noticed that locking the object graph to reattach it to the current session will initialize all proxies, i.e. load a lot of data from the database (and use a lot of heap memory, as the data contains a lot of BLOBs). This basically disables lazy-loading. Just to make sure that this is not a problem with my code:

* Could somebody confirm that this is Hibernate's intended behaviour?

* If yes, then what's so bad about reattaching uninitialized proxies, i.e. why does the proxy care via which session it lazy-loads objects? I am sure that I am missing something here and I am eager to learn.

Oh, while we are at this. I also ran into the dirty collections problem. You cannot reattach them. I worked around this by creating sort of a copy-on-write mechanism for my database objects based on Javassist. Sort of my own lazy-loading instrumentation for my domain objects that lazy-loads from Hibernate-managed backing objects which then lazy-load from the database. (Note the high geek value of this solution!) Upon saving, I copy the content of my objects into the Hibernate-managed objects and persist the changes. Works nicely, but I might be missing something here. So:

* What's so bad about reattaching dirty collections? I am concerned that I am missing a subtle failure mode of my work-around here. There has to be a reason why Hibernate does not support this.

Thanks,
Thomas


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.