openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oliver Ringel (JIRA)" <>
Subject [jira] Commented: (OPENJPA-1787) Bean validation fails merging a new entity
Date Wed, 02 Mar 2011 19:23:36 GMT


Oliver Ringel commented on OPENJPA-1787:

I finally found the place in the source code where the data gets lost.

If you merge a new entity the BrokerImpl first tries to attach the entity via the AttachManager.
The AttachManager uses an AttachStrategy to persist the new entity. 

Here ist the code snippet from the org.apache.openjpa.kernel.AttachStrategy class with my

    protected StateManagerImpl persist(AttachManager manager,
        PersistenceCapable pc, ClassMetaData meta, Object appId, 
        boolean explicit) {
        PersistenceCapable newInstance;

        if (!manager.getCopyNew())
            newInstance = pc;                                                            
          <--- calling this would fix the issue 
        else if (appId == null) {
            newInstance = pc.pcNewInstance(null, false);                                <---
but this is called, pc.pcNewInstance returns an new instance, is set to null
            newInstance = pc.pcNewInstance(null, appId, false);

        return (StateManagerImpl) manager.getBroker().persist                       <--
this calls finally BrokerImpl.persistInternal(...) and fails because is null 

            (newInstance, appId, explicit, manager.getBehavior());

For my testcases this issue could be fixed by replacing the first if statement with "if (manager.getCopyNew())".
I'm absolutely not sure, if it is really that easy. I guess not.

Maybe another good place to fix the problem is EntityManagerImpl.merge() which also sets the
AttachManager's copyNew flag.

Please could someone with more insight into openjpa verify this solution.

> 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
>            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