[ 
https://issues.apache.org/jira/browse/OPENJPA-673?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12619733#action_12619733
 ] 

Pinaki Poddar commented on OPENJPA-673:
---------------------------------------

Following simple Test
===========================================================
        public void testSimpleMerge() {
                EntityManager em1 = emf.createEntityManager();
                em1.getTransaction().begin();
                PObject pc = new PObject();
                pc.setData("Persist NEW");
                em1.persist(pc);
                em1.getTransaction().commit();
                
                EntityManager em2 = emf.createEntityManager();
                em2.getTransaction().begin();
                pc.setData("Modified");
                em2.merge(pc);
                em2.getTransaction().commit();
        }
========================================================
with a Simple entity
========================================================
@Entity
public class PObject {
        @Id
        @GeneratedValue
        private long id;
        
        private String data;
        
        @Version
        private int version;
}
==================================================

fails with 
<openjpa-1.3.0-SNAPSHOT-r422266:681977M nonfatal user error> 
org.apache.openjpa.persistence.InvalidStateException: The generated value 
processing detected an existing value assigned to this field: 
jiraXXX.PObject.id.  This existing value was either provided via an initializer 
or by calling the setter method.  You either need to remove the @GeneratedValue 
annotation or modify the code to remove the initializer processing.
        at 
org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:483)
        at 
org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:463)
        at 
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignObjectId(JDBCStoreManager.java:682)
        at 
org.apache.openjpa.kernel.DelegatingStoreManager.assignObjectId(DelegatingStoreManager.java:134)
        at 
org.apache.openjpa.kernel.StateManagerImpl.assignObjectId(StateManagerImpl.java:519)
        at 
org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2823)
        at org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:39)
        at 
org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:959)
        at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1948)
        at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1908)
        at 
org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1826)
        at 
org.apache.openjpa.kernel.LocalManagedRuntime.commit(LocalManagedRuntime.java:81)
        at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1350)
        at 
org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:877)
        at 
org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:512)
        at jiraXXX.TestMerge.testSimpleMerge(TestMerge.java:24)
        

"Making simple things easy, and difficult things possible" -- a sign of good 
design

> Entity using Generated Value for primary key and a Version field and no 
> DetachedStae fails to merge 
> ----------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-673
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-673
>             Project: OpenJPA
>          Issue Type: Bug
>            Reporter: Pinaki Poddar
>             Fix For: 1.2.0
>
>
> Entities using GeneratedValue for primary key, a version field an dno 
> detached state fails to merge.
> The issue lies with identifying :"what makes a new instance?"
> It is not obvious why VersionAttachStrategy does not use version field to 
> detect newness. Instead it depends on detached state which is obviously null 
> for instances not using a Detached State.
> Can someone shade some light on why VersionAttachStrategy ignores version 
> field to detect newness? 
>  

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to