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: Best way to prevent NonUniqueObjectExceptions
PostPosted: Wed Mar 23, 2005 7:12 pm 
Newbie

Joined: Thu Oct 21, 2004 3:03 pm
Posts: 13
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.


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.