Dear All,
I have a tricky little problem. An object is loaded and then the session is closed. Later a new session opens and the object needs to be attached to this new session so that lazy collections work. This is no problem with the Lock command.
However, by this time I've got a
non-proxified version the original object. It's still got proxified collections within it that need re-attaching and presumably there is sill a proxy wrapper for it floating around somewhere (even if the original session is closed). If I want to use Lock, I need this proxified reference again.
So, my question:
How do you lookup the proxified reference to a POJO when you only have the original pojo to hand? I also don't have a reference to the original session, so I can't do a new lookup.
Any thoughts?
Now I know that this sounds like my architecture is a bit screwy, but it's really not. It's all very clean actually. Perhaps too clean : this problem is the result of a very clear seperation of GUI and Domain Model code...
My only workarround (not yet tested) is to use a listener to watch out for LoadEvents and SaveOrUpdateEvents on the POJO and quickly stash a reference to it's proxified version in the pojo itself. Then I can do something like..
Code:
session.lock(object.getProxifiedReference(), LockMode.NONE);
This is clearly a hack. I hope I'm missing a Hibernate feature....
I look forward to hearing your thoughts.
Regards,
Ben.