-->
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: How to clear session cache
PostPosted: Tue Mar 01, 2011 11:17 pm 
Newbie

Joined: Fri Feb 18, 2011 12:25 am
Posts: 8
Hi all,

I have come across a scenerio where a particular database table can be accessed using NHibernate as well as ADO.Net (Com+). Whenever user perform insert operation using Nhibernate followed by insert using ADO.Net gives error "Violation of PRIMARY KEY constraint '<TableName>'. Cannot insert duplicate key in object"

It seems there is some caching issue and the primary Key ID being genreated by the NHibernate code is already being used by the ADO.Net.

Can someone please guide with the syntax for Clear/Flush/Evict

Thanks

_________________
christian louboutin


Top
 Profile  
 
 Post subject: Re: How to clear session cache
PostPosted: Thu May 05, 2011 9:54 am 
Newbie

Joined: Thu May 05, 2011 1:38 am
Posts: 7
This will clear your cashe for all objects:
Code:
session.Clear();

So next time you load any object associated with this session it, it will be loaded directly from DB.
If you want to only to reload specific object (and don't clear whole cashe) use:
Code:
session.Refresh(item);


But i think, in your case you have changed PK or inserted object with the same ID.
You could try, remove your "item" from session
Code:
session.Evict(item);

before saving it with non-hibernate code, but probably DB will throw exception.
So it is not good idea to change ID of proxy objects.

Hope it helps a little bit.


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.