With Hibernate validation, can I query the entity being validated?
问题 I have an entity on which I need to implement the following constraint: "There may only ever be one record for any combination of columns X and Y, for which column Z is null if the record is of type A." The last part turns this from a simple uniqueness constraint to something more complex. I'm writing a custom Hibernate validator to check it. What I'm doing is: @Override public boolean isValid(MyEntity value, ConstraintValidatorContext context) { Query query = DB.createQuery( // DB is just a