[hibernate-dev] @Where clause and finding an entity

Vlad Mihalcea mihalcea.vlad at gmail.com
Fri Feb 17 07:50:09 EST 2017


Hi,

I'm testing the way @Where annotation works, and I found the following
scenario:

If we have an entity annotated like this:

@Where(clause = "deleted = false")

@SQLDelete(sql = "UPDATE tag set deleted = true where id = ?")

If the entity was previously deleted and I try to load it in a new
Persistence Context:

assertNull(entityManager.find(Tag.class, "Misc"));

The entity is fetched successfully, and the assert fails.

The only way to make it work is if I override the load query using the
@Loader annotation:

@Loader(namedQuery = "findTagById")
@NamedQuery(name = "findTagById", query = "select t from Tag t where
t.id = ? and t.deleted = false")

Is this the expected behavior or is it a bug?

Vlad


More information about the hibernate-dev mailing list