Reputation: 2955
I have a small system consisting of a .net client and a java web service.
The .net client inserts an object into the database, and then calls the web service. The web service tries to retrieve this object using hibernate. First time it works fine, but every other time it says that there is no object with the given identifier.
I have checked the database manually and the row is indeed there! (I debugged the web service and checked for the row even before a session was opened).
SOLUTION
Added this to the hibernate config file
<property name="connection.isolation">1</property>
Here's what I've tried so far:
Here's the failing code:
Session session = Program.HibernateUtil.getSessionFactory().openSession();
try
{
return (Alert)session.load(Alert.class, id);
} ...
Upvotes: 3
Views: 399
Reputation: 34321
It looks like the second level cache (the one associated with the session factory) should be disabled so the only other thing I can suggest is to explicitly clear the cache with the call:
sessionFactory.evict(Alert.class)
Note: read the comments for the full answer.
Upvotes: 2
Reputation: 403581
Firstly, don't use Session.load()
, use Session.get()
. load()
should only be used in very particular situations, and this ain't one of them.
Secondly, are you performing both operations within the same Session? If so, Hibernate will cache the entity after the first operation. There's no way to stop it doing this. However, you can use evict()
on the Session to forceably kick the entity out of the session cache.
Upvotes: 1
Reputation: 58128
Try setting this hibernate property:
hibernate.cache.provider_class = org.hibernate.cache.NoCacheProvider
Upvotes: 0