-
Bug
-
Resolution: Won't Do
-
Major
-
None
-
7.1.1.Final
-
None
Per JPA 2.0 spec 3.6.1.2 Requirements for Automatic Validation upon Lifecycle Events, the "persistence provider must throw the javax.validation.ConstraintViolationException" ... and the validation must occur "immediately after the point" where callback method invocations, such as PrePersist have been completed.
Having a Member entity with some @NonNull validator present on one of its fields, the following test shows the javax.validation.ConstraintViolationException is not thrown while invoking persist, but later inside flush():
try { System.out.println("XXX: before em.persist()"); em.persist(new Member()); System.out.println("XXX: after em.persist()"); em.flush(); System.out.println("XXX: after em.flush()"); } catch(javax.validation.ConstraintViolationException x) { System.out.println("XXX: Constraint violation!"); }
@Entity @XmlRootElement @Table(uniqueConstraints = @UniqueConstraint(columnNames = "email")) public class Member implements Serializable { ... @NotNull @NotEmpty @Email private String email; ... @PrePersist public void prePersist() { System.out.println("XXX: prePersist"); } }