-->
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: NonUniqueObjectException when trying to re-import db table
PostPosted: Fri Nov 09, 2007 9:07 am 
Newbie

Joined: Tue Sep 18, 2007 11:25 am
Posts: 3
Hi!

I try to do the following:

1. Delete table 'category':
currentSession.createQuery("delete from Catalog").executeUpdate()

2. Re-insert Category data:
currentSession.save(new Catalog(pk));

I get this exception:

Code:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session


Obviously, Hibernate doesn't realize that I deleted all catalogs in step 1, and still has category instances in its cache.
I try to flush() after each step, evict() and refresh() the new catalog, whithout success. When I try to refresh() the new catalog to make Hibernate aware that it does not exist in the DB anmore, I get
Code:
org.hibernate.UnresolvableObjectException: No row with the given identifier exists


All of this is executed in a single session in a single transaction, since it is a nightly DB import. I use hibernate-3.1.3.

Any solutions?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 12, 2007 6:57 am 
Newbie

Joined: Tue Sep 18, 2007 11:25 am
Posts: 3
Ok, I have done some research and now I know that Hibernate does not delete entitites from its session when they are deleted with HQL mass deletes.

I am now doing the deletion with a ScrollableResults, deleting every entity one by one, which works but sucks.
The sessions evict() method only accepts single entitites, and the SessionFactories mass evict facilities only affect the 2nd level cache, so those methods are no solution.

Is there a workaround? I figure there must be one, since this is probably a common usecase...


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.