Bean Validation add-on & unique constraints

Is there a way to handle unique contraints with this add-on ?

@Table(uniqueConstraints = { @UniqueConstraint(columnNames = {
		fieldA, fieldB }) })
public class Image {

Sorry for the late reply.

The bean validation add-on does not know about the implementations of the validation annotations, it just calls the generic JSR-303 API. However, your example is not using standard JSR-303 validation annotations but something database specific (Hibernate?), and probably not JSR-303 compliant even if Hibernate validation engine could handle it when storing entities in the database. Note that JSR-303 annotations normally only apply to fields or methods, not on classes.

In any case, it would be hard to apply database-specific validations generically during UI code execution - how should they be checked, how should they relate to transactions, …

You are totally right. Indeed Hibernate Validation do not handle this “UniqueConstraint”, it is taken into account only on table auto creation (all I have got is an jdbc exception when creating a row which doesn’t respect the constraint). So we could assume that it is business logic to do such control…which I did in my business layer.