openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeremy Bauer (JIRA)" <>
Subject [jira] Commented: (OPENJPA-1787) Bean validation fails merging a new entity
Date Thu, 10 Mar 2011 19:06:59 GMT


Jeremy Bauer commented on OPENJPA-1787:

I tracked down the source of the problem.  When merging a new entity, OpenJPA persists a new
"empty" entity, sets (or retrieves) an ID for the new entity, and then merges in the object
passed in.  The problem is that the during the persist of the empty entity, a PRE_PERSIST
lifecycle event gets fired, causing validation to occur.  I've found that not only is validation
occurring prematurely, but OpenJPA violates the JPA specification for the PrePersist callback
as well.  

<jpa 1.0 & 2.0 spec - section 3.5.2>
For entities to which the merge operation has been applied and causes the creation of newly
managed instances, the PrePersist callback methods will be invoked for the managed instance
after the entity state has been copied to it.
<jpa 1.0 & 2.0 spec - section 3.5.2/>

By adding this simple callback to the Person class, it showed that a PrePersist callback occurred
before the entity was fully populated. 
class Person {

    public void prePersist() {
        System.out.println("PrePersist getName()=" + this.getName());

Result:  PrePersist getName()=null

I think the solution will be to disable this callback for the case where a new entity is created
specifically for the purposes of a merge.  Working on a fix...

> Bean validation fails merging a new entity
> ------------------------------------------
>                 Key: OPENJPA-1787
>                 URL:
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa, kernel
>    Affects Versions: 2.0.1, 2.1.0, 2.2.0
>            Reporter: Oliver Ringel
>            Assignee: Jeremy Bauer
>            Priority: Critical
>         Attachments: com.example.TestEmployeeDAO.txt, openjpa-1787.tar, testcase-openjpa-1787.tar
> The bean validation is not working correctly
> If you try to merge a new entity.
>         EntityManager em = entityManagerFactory.createEntityManager();
>         Person person = new Person();
>         person.setName("Oliver");                               // is annotated
>         person = em.merge(person);                            
> you get a ConstraintValidationException, although name is set. 

This message is automatically generated by JIRA.
For more information on JIRA, see:

View raw message