Hi all,
I can't find a proper way to check if a record on db has be deleted.
I have a simple mapped class, with no parent, childs, collections.. just simple properties.
I want simply have a method that check if a particular entity is still on db or not (a row can be deleted from another application or from the db administrator, for example).
I'm using this code:
Code:
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
ZipFile zipFile = (ZipFile) HibernateUtil.getSessionFactory().getCurrentSession().createQuery(
"select zipFile from ZipFile zipFile where zipFile.name = :fileName")
.setParameter("fileName", fileName)
.uniqueResult();
HibernateUtil.getSessionFactory().getCurrentSession().close();
return zipFile != null;
The code always retrieve the row even if it's deleted from db..
I tried to work with the cache, using clear(), or to evict the zipFile and to load() or get() the entity with the previously retrieved id.. always the entity is retrieved.
What i'm doin wrong?
Thanks in advance.