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
|