I have an entity using the @Where annotation as the following code
@OneToMany(fetch=FetchType.LAZY, mappedBy = "otherthing") @Where(clause="FLAG_A='N' AND FLAG_B='N'") private List<OtherThing> listOtherThing;
It works when I load entity from database. In a transaction I modify this list, changing the @Where condition clauses to the ‘Y’ value
OtherThingRepository repo; OtherThing ex=repo.findById(123); ex.setFlagA("Y");
and when I reload the main entity (still in the transaction)
MainObjectRepository repo; MainObject ex=repo.findById(456); ex.getListOtherThings(); // <--- HERE
I can see this list with updated values, while these new values should be excluded by the annotation.
If I get the entity after this transaction, the annotation correctly works and I cannot see the list with flags different from ‘N’ value.
It seems like the annotation only works when there is the first load of the entity, but updates aren’t managed during transaction. Any ideas?