Kristian wrote:Quote:
David,
I converted from Hibernate v2.x to v3 and ran into problems with the session.load returning proxies when lazy is enabled. My workaround was to use Hibnernate.initialize( ...), so Exceptions are thrown when you would expect them (when using session.load). Is this a good / the right solution?
--
Thanks,
Kristian
David wrote:Quote:
Some people have not noticed (or read about) the change to lazy=true being the default in H3. You could call initialise to verify the objects existance though I feel its not the best approach as I do not like using exceptions to indicate anything other than a fault.
I agree that it doesn't feel like the best approach. But as you say, exceptions should indicate a fault and there are many use cases where not getting the object indicates a fault. My impression is that the load method is for exactly this. Since it returns a proxy, we need some way of throwing an exception if the object doesn't exist. I'm probably misunderstanding something here, but for me it doesn't make any sense that the load method changes behavior depending on if you use lazy loading or not.
David wrote:Quote:
If you want to load the object and make sure that it is present then use session.get() which will return a null if the object did not exist at the time of the read transaction was performed.
Yes, I use the get() method when this behavior is what I'm looking for. But as I mentioned above, there are cases when non-existence of the object indicates a fault and should result in an exception.
You could check for null and throw an exception accordingly. But this becames very tedious and repetitive.
Best regards,
Kristian