Hi,
On a project we are facing the following issue (Hibernate 3.5.0-Final). We are deleting entities using a HQL query (delete e from Entity e where ...).
Code:
Entity e = new Entity();
s.persist(e);
In a new transaction I do:
Code:
Entity e = s.get(Entity.class, id);
assertNotNull(e); //This is working
int nb = s.createQuery("delete e from Entity e").executeUpdate();
assertEquals(1, nb);
s.flush();
e = s.get(Entity.class, id);
assertNull(e); //This is NOT working as the entity is still in the cache
Of course Hibernate is not able to know what are the deleted entities so I would like to purge the cache manually.
I tried to use the evict method:
Code:
Entity e = s.get(Entity.class, id);
assertNotNull(e); //This is working
int nb = s.createQuery("delete e from Entity e").executeUpdate();
assertEquals(1, nb);
s.flush();
s.evict(Entity.class); // Try to purge the cache
e = s.get(Entity.class, id);
assertNull(e); //This is NOT working as the entity is still in the cache
So it seems the evict call is not taken into account. The only workaround I found is to replace the evict() call by clear() but clear will purge all entities and I would like to only purge Entity.class instances.
Do you know if this is a bug or if I did something wrong in the use of evict?
Thanks
Julien