-->
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: SessionImpl.Evict not evicting ?!?
PostPosted: Wed Jun 08, 2005 3:56 pm 
Newbie

Joined: Wed Jun 08, 2005 3:36 pm
Posts: 4
Hello,

I've got a problem with SessionImpl not evicting newly created objects... but first thing first...

1. My objects have composite Ids

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="hibernate.UserWord, hibernate" table="user_word">
<composite-id>
<key-property name="UserId" column="user_id" />
<key-property name="Word" column="word" />
</composite-id>

<property name="Score" column="score"></property>
</class>
</hibernate-mapping>

2. In a loop I create new object and do

try {
session.Save(uw); session.Flush();
}
catch (Exception e)
{
session.Evict(uw);
}

I do end up with duplicate objects and get the exception, so session.Evict() is called and I see object removed, but session.insertions still holds something about that duplicate object I am evicting. So next time I call session.Flush() I get the same exception again and again....

Work around is to recreate the session instead of evicting bad object, but this breaks transactions that I want (I did started with transactions and the example above is simplified version so the problem would be obvious)

Just to be sure I implemented

public override bool Equals(Object obj)
{
if (obj == null || GetType() != obj.GetType()) return false;
UserWord uw = (UserWord)obj;
return Word.Equals(uw.Word) && UserId.Equals(uw.UserId);
}

and

public override int GetHashCode ()
{
return Word.GetHashCode() ^ UserId.GetHashCode();
}

but it didn't change anything.

Since I am a novice with NHibernate I am not sure if it is a bug or I am abusing NHibernate is some way, but I don't see what I am doing wrong.

Any ideas?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 10, 2005 1:27 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You shouldn't reuse the session after an exception, it's not supported. You have to rollback the transaction, close the session, and start a new one. Don't worry about session creation, it's a relatively fast operation.


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.