Hibernate version: 2.1.8
I encountered a situation which initially produced NonUniqueObjectExceptions, and after some digging I was able to track down the cause.
I have an object A which has a one-to-one, cascade=none mapping with object B. Object A is being edited through my application, and for validation reasons I have to incidentally retrieve a list of B objects. This of course causes a fetch of it's corresponding A object, and so now I have two instances of A in my session (the one I am actively editing, and the one which I don't really want as a result of the B object fetch).
Using the brute-force method of explicitly evicting B and B.A, everything is working fine. I don't want to enable cascade for the A/B relationship, but I don't really want to have to worry about manually evicting associated objects everywhere either.
Is there a way I can initially retrieve B objects and avoid the implicit fetch of the corresponding one-to-one A object? Or, is there a way I can tell Hibernate to give me a list of transient B objects, automatically detaching from the session?
FYI, I'm using Spring to handle my Hibernate services and transactions (not sure if that matters).
Thanks for any help or suggestions.
|