-->
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: throw NonUniqueObjectException Excption when save a record
PostPosted: Tue Aug 09, 2005 12:28 am 
Newbie

Joined: Mon Aug 08, 2005 11:54 pm
Posts: 1
when I delete a recrod first and then add it back, system will throw a exception of NonUniqueObjectException, all implement in same Session and Transaction.

I user HQL delete records as fellow:

Query query = session.createQuery("delete from Table where Col=:col");
query.setString("col", "xxx");
int count = query.executeUpdate();

then I will add a record which exists in deleted list. I use session same as delete statement.
Table t = new Table("xxx");
session.save(t);

when commit transaction, the NonUniqueObjectException will be throwed out. can you help me.

DataBase: MySQL 5.1. Hibernation 3.1


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 09, 2005 3:08 am 
Pro
Pro

Joined: Mon Jan 24, 2005 5:39 am
Posts: 216
Location: Germany
Hi Anny,

seems to be right.
You should not create two objects with the
same identifier and attach them to the same
session. The delete does not remove the instances
in the session cache, instead it alters their
state from "saved" to "deleted".
To save your instance again just use something
like:

Code:
User user = new User(0);
session.save(user);

session.createQuery("delete from User");
query.executeUpdate();

session.save(user);

Hope this helps.


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.