openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gurkan Erdogdu (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (OPENJPA-673) Entity using Generated Value for primary key and a Version field and no DetachedStae fails to merge
Date Wed, 12 Jun 2013 05:35:20 GMT

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

Gurkan Erdogdu edited comment on OPENJPA-673 at 6/12/13 5:34 AM:
-----------------------------------------------------------------

Hello Kevin

Issue is that

- Persist a new entity in a new transaction. Entity name is : Address
- Merge a new entity which includes List<Address> in a new transaction. It throws the
exception as :

I tried all 2.x.x versions, all of them are failed! (I said that 2.1.1 works but this is my
fault, it does not work!)

Jun 11, 2013 11:55:53 AM org.apache.geronimo.transaction.manager.TransactionImpl beforeCompletion
WARNING: Unexpected exception from beforeCompletion; transaction will roll back
<openjpa-2.1.1-r422266:1148538 nonfatal user error> org.apache.openjpa.persistence.InvalidStateException:
Primary key field Address.id of Address@b236ac has non-default value. The instance life cycle
is in PNewProvisionalState state and hence an existing non-default value for the identity
field is not permitted. 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:489)
	at org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:469)
	at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignObjectId(JDBCStoreManager.java:769)
	at org.apache.openjpa.kernel.DelegatingStoreManager.assignObjectId(DelegatingStoreManager.java:135)
	at org.apache.openjpa.kernel.StateManagerImpl.assignObjectId(StateManagerImpl.java:605)
	at org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2966)
	at org.apache.openjpa.kernel.PNewProvisionalState.nonprovisional(PNewProvisionalState.java:45)
	at org.apache.openjpa.kernel.StateManagerImpl.nonprovisional(StateManagerImpl.java:1222)
	at org.apache.openjpa.kernel.SingleFieldManager.preFlushPC(SingleFieldManager.java:806)
	at org.apache.openjpa.kernel.SingleFieldManager.preFlushPCs(SingleFieldManager.java:751)
	at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:653)
	at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:578)
	at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:494)
	at org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2971)
	at org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:40)
	at org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:1047)
	at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2096)
	at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2056)
	at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1974)
	at org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:527)
	at org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:512)
	at org.apache.geronimo.transaction.manager.TransactionImpl.beforePrepare(TransactionImpl.java:413)
	at org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.java:262)
	at org.apache.geronimo.transaction.manager.TransactionManagerImpl.commit(TransactionManagerImpl.java:252)
	at org.apache.openejb.core.transaction.JtaTransactionPolicy.completeTransaction(JtaTransactionPolicy.java:328)
	at org.apache.openejb.core.transaction.TxRequired.commit(TxRequired.java:75)
	at org.apache.openejb.core.transaction.EjbTransactionUtil.afterInvoke(EjbTransactionUtil.java:76)
	at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:259)
	at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:191)
	at org.apache.openejb.core.ivm.EjbObjectProxyHandler.synchronizedBusinessMethod(EjbObjectProxyHandler.java:246)
	at org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:241)
	at org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:83)
	at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:279)

Code example:
@Stateless class PersoneController{
     //JTA based entity manager
     @PersistenceContext EntityManager em;
     
     //Person is a new object 
     public void merge(Person person){
        em.merge(person);
     }

}

class Client{

   public void main(){
      //Address is already in database 
      Address address = EntityManager.find(Address.class,1);

      Person p = new Person();
      p.getAddresses.add(address);
      PersonController.merge(p); //This throws exception as above
      
  }
}

                
      was (Author: gerdogdu):
    Hello Kevin

Issue is that

- Persist a new entity in a new transaction. Entity name is : Address
- Merge a new entity which includes List<Address> in a new transaction. It throws the
exception as :

I tried all 2.x.x versions, all of them are failed! (I said that 2.1.1 works but this is my
fault, it does not work!)

Jun 11, 2013 11:55:53 AM org.apache.geronimo.transaction.manager.TransactionImpl beforeCompletion
WARNING: Unexpected exception from beforeCompletion; transaction will roll back
<openjpa-2.1.1-r422266:1148538 nonfatal user error> org.apache.openjpa.persistence.InvalidStateException:
Primary key field tr.com.mechsoft.efatura.web.jpa.SentInvoice.id of tr.com.mechsoft.efatura.web.jpa.SentInvoice@b236ac
has non-default value. The instance life cycle is in PNewProvisionalState state and hence
an existing non-default value for the identity field is not permitted. 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:489)
	at org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:469)
	at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignObjectId(JDBCStoreManager.java:769)
	at org.apache.openjpa.kernel.DelegatingStoreManager.assignObjectId(DelegatingStoreManager.java:135)
	at org.apache.openjpa.kernel.StateManagerImpl.assignObjectId(StateManagerImpl.java:605)
	at org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2966)
	at org.apache.openjpa.kernel.PNewProvisionalState.nonprovisional(PNewProvisionalState.java:45)
	at org.apache.openjpa.kernel.StateManagerImpl.nonprovisional(StateManagerImpl.java:1222)
	at org.apache.openjpa.kernel.SingleFieldManager.preFlushPC(SingleFieldManager.java:806)
	at org.apache.openjpa.kernel.SingleFieldManager.preFlushPCs(SingleFieldManager.java:751)
	at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:653)
	at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:578)
	at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:494)
	at org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2971)
	at org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:40)
	at org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:1047)
	at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2096)
	at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2056)
	at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1974)
	at org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:527)
	at org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:512)
	at org.apache.geronimo.transaction.manager.TransactionImpl.beforePrepare(TransactionImpl.java:413)
	at org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.java:262)
	at org.apache.geronimo.transaction.manager.TransactionManagerImpl.commit(TransactionManagerImpl.java:252)
	at org.apache.openejb.core.transaction.JtaTransactionPolicy.completeTransaction(JtaTransactionPolicy.java:328)
	at org.apache.openejb.core.transaction.TxRequired.commit(TxRequired.java:75)
	at org.apache.openejb.core.transaction.EjbTransactionUtil.afterInvoke(EjbTransactionUtil.java:76)
	at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:259)
	at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:191)
	at org.apache.openejb.core.ivm.EjbObjectProxyHandler.synchronizedBusinessMethod(EjbObjectProxyHandler.java:246)
	at org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:241)
	at org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:83)
	at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:279)

Code example:
@Stateless class PersoneController{
     //JTA based entity manager
     @PersistenceContext EntityManager em;
     
     //Person is a new object 
     public void merge(Person person){
        em.merge(person);
     }

}

class Client{

   public void main(){
      //Address is already in database 
      Address address = EntityManager.find(Address.class,1);

      Person p = new Person();
      p.getAddresses.add(address);
      PersonController.merge(p);
      
  }
}

                  
> 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
>
> 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.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message