-->
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.  [ 2 posts ] 
Author Message
 Post subject: Why don't I get a NonUniqueObjectException ?
PostPosted: Mon Aug 13, 2007 12:27 pm 
Newbie

Joined: Mon Mar 01, 2004 9:59 am
Posts: 8
Hi,

I just played around to understand circumstances where a NonUniqueObjectException is thrown and figured out that the following snipped doesn't end up with such an exception but with having two different rows in the DB.

Why does this not provoke a NonUniqueObjectException ?

Regards
Manfred


<snipped>

SessionFactory sf;
Session s;
Transaction t;
Pizza p1, p2;
sf = HibernateUtil.getSessionFactory();

/*
* Session 1
*/
s = sf.openSession();
t = s.beginTransaction();

p1 = new Pizza();
p1.setName("Test-Pizza");
s.save(p1);

t.commit();
s.clear();
s.close();

/*
* Session 2
*/
s = sf.openSession();
t = s.beginTransaction();

p2 = (Pizza)s.load(Pizza.class, p1.getId());
s.save(p1);

t.commit();
s.close();

</snipped>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 13, 2007 3:51 pm 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
I think because you're calling save (rather than update, merge or saveOrUpdate) you're telling hibernate the detatched instance p1 is a new object. Hence, when save, it gets a new ID and doesn't clash with the previously loaded p2.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.