I'm working on an inherited codebase of a Hibernate (3.3.2.GA - and since the software should be shipped rather soon there is no time to update) application in which I'm trying to delete some objects from the database. After deleting the Objects via a HQL query the objects can still be retrieved from the hibernate session via the findById method of the (MyEclipse generated) dao. Is there anything I'm missing to get the Objects to disappear? Do I need to invalidate some caches? After waiting a seemingly random while (between about 30 and 300 seconds) the findById starts to return null. The objects use a composite id. Could that be a Problem?
Here is the code to delete the objects:
Query query = objDao.getSession()
.createQuery("DELETE FROM Obj i WHERE i.id.uuid = ? AND i.userId = ?");
query.setString(0, obj.getUuid());
query.setInteger(1, currentUserId);
objDao.getSession().beginTransaction();
int numRows = query.executeUpdate();
System.out.println("Deleted " + numRows + " Obj for uuid " + obj.getUuid() + " (user: "
+ currentUserId+ ")");
objDao.getSession().flush();
objDao.getSession().getTransaction().commit();
Here is the code that is called afterwards to retrieve the objects from the database. I would expect this to return null but it does not.
objDao.findById(new ObjectId(temp.getId(), temp.getUuid()))
objDao.findById is implemented as such:
public Obj findById(com.application.ObjectId id) {
Obj instance = (Obj) getSession() // this returns a org.hibernate.Session
.get("com.application.Obj", id);
return instance;
}
Any help is appreciated!