[
https://issues.jboss.org/browse/AS7-4576?page=com.atlassian.jira.plugin.s...
]
Marek Schmidt edited comment on AS7-4576 at 4/20/12 10:24 AM:
--------------------------------------------------------------
It does, that's where the "XXX: prePersist" comes from in the logs, so the
pre-persist happens during em.persist(), but there is no contraint violation immediately
after that:
15:31:15,065 INFO [stdout] (http-dhcp-26-127.brq.redhat.com-127.0.0.1-8080-2) XXX: before
em.persist()
15:31:15,066 INFO [stdout] (http-dhcp-26-127.brq.redhat.com-127.0.0.1-8080-2) XXX:
prePersist
15:31:15,068 INFO [stdout] (http-dhcp-26-127.brq.redhat.com-127.0.0.1-8080-2) XXX: after
em.persist()
15:31:15,074 INFO [stdout] (http-dhcp-26-127.brq.redhat.com-127.0.0.1-8080-2) XXX:
Constraint violation!
{noformat}
...
@Entity
@XmlRootElement
@Table(uniqueConstraints = @UniqueConstraint(columnNames = "email"))
public class Member implements Serializable {
...
@PrePersist
public void prePersist() {
System.out.println("XXX: prePersist");
}
}
{noformat}
was (Author: maschmid):
It does, that's where the "XXX: prePersist" comes from in the logs, so
the pre-persist happens during em.persist():
15:31:15,065 INFO [stdout] (http-dhcp-26-127.brq.redhat.com-127.0.0.1-8080-2) XXX: before
em.persist()
15:31:15,066 INFO [stdout] (http-dhcp-26-127.brq.redhat.com-127.0.0.1-8080-2) XXX:
prePersist
15:31:15,068 INFO [stdout] (http-dhcp-26-127.brq.redhat.com-127.0.0.1-8080-2) XXX: after
em.persist()
15:31:15,074 INFO [stdout] (http-dhcp-26-127.brq.redhat.com-127.0.0.1-8080-2) XXX:
Constraint violation!
{noformat}
...
@Entity
@XmlRootElement
@Table(uniqueConstraints = @UniqueConstraint(columnNames = "email"))
public class Member implements Serializable {
...
@PrePersist
public void prePersist() {
System.out.println("XXX: prePersist");
}
}
{noformat}
No ConstraintViolationException thrown by EntityManager persist upon
pre-persist constraint violation
-----------------------------------------------------------------------------------------------------
Key: AS7-4576
URL:
https://issues.jboss.org/browse/AS7-4576
Project: Application Server 7
Issue Type: Bug
Components: JPA / Hibernate
Affects Versions: 7.1.1.Final
Environment: as7.1.2-SNAPSHOT (2012-04-20)
c525e538fda12bde76b44a6db4f61d55105c1cea, hibernate4
Reporter: Marek Schmidt
Assignee: Scott Marlow
Attachments: jboss-as-kitchensink.war
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():
{noformat}
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!");
}
{noformat}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see:
http://www.atlassian.com/software/jira