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 Thu, 10 Mar 2011 13:43:59 GMT


Oliver Ringel commented on OPENJPA-1787:

Hi Michael,
thank you for your answer. I thought that it would not be so easy to solve this issue. Unfortunately.

I agree with you that the main problem here is that a copy action is missing and I guess AttachStrategy.persist
is the right place to add some kind of copy functionality.

I started looking into the source code of the enhanced class from the test. PersistenceCapable
declares a public method to copy fields (pcCopyFields(...)).
Unfortunately you can't use in AttachStrategy.persist, because the entity to persist has no
statemanager at this point (an exception InvalidStateException will be the result).

My suggestion is to modify the class enhancement and remove the StateManager check in pcCopyFields
(I don't see the need for this check). 
Afterwards you can use pcCopyFields in AttachStrategy.persist by adding something like 

        if (manager.getCopyNew()) {
            int[] fields = new int[meta.getFields().length];
            for (int i = 0; i < fields.length; i++)
                fields[i] = i;
            newInstance.pcCopyFields(pc, fields);

This solution works for my testcase.

As an alternative you can modify (or add an additional) newInstance to copy the data.

I have no real experience with OpenJPA. Perhaps there is a much better 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