unable to persist a new entity, when there is a entity with id value 0 loaded 
in persistent context
---------------------------------------------------------------------------------------------------

                 Key: OPENJPA-330
                 URL: https://issues.apache.org/jira/browse/OPENJPA-330
             Project: OpenJPA
          Issue Type: Bug
          Components: jpa
    Affects Versions: 1.0.0
            Reporter: Henry Lai


unable to persist a new entity, when there is a entity with id value 0 loaded 
in persistent context.
The entity is declared to use generated value sequence strategy.

<1.0.0-SNAPSHOT-SNAPSHOT nonfatal store error> 
org.apache.openjpa.persistence.EntityExistsException: An object of type 
"ptp.test.issue7.T7Entity" with oid "ptp.test.issue7.T7Entity-0" already exists 
in this context; another cannot be persisted.


        public void testEntityWithZeroID(){
                PersistenceProviderImpl openJPA = new PersistenceProviderImpl();
                EntityManagerFactory factory = 
                        openJPA.createEntityManagerFactory("test", 
"ptp/test/issue7/persistence.xml",
                                                System.getProperties() );
                
        EntityManager em = factory.createEntityManager();
        em.getTransaction().begin();
                Query deleteStmt = em.createNativeQuery("delete from T7Entity");
                deleteStmt.executeUpdate();
                em.getTransaction().commit();
                
        em = factory.createEntityManager();
        em.getTransaction().begin();
        Query createStmt = em.createNativeQuery("insert into T7Entity 
(S_ID,NAME) values (0,'MICKEY')");
        createStmt.executeUpdate();
        em.getTransaction().commit();
        
        
        em = factory.createEntityManager();
        em.getTransaction().begin();
        Query query = em.createQuery("select obj from T7Entity obj");
        List resultList = query.getResultList();
        
        T7Entity aEntity = new T7Entity();
        aEntity.setName("Minnie");
        
        em.persist(aEntity);    // fails here
        
        em.getTransaction().commit();
        
        em.close();
        }



        <entity class="T7Entity">
                <table name="T7Entity" />
                <attributes>
                        <id name="id">
                                <column name="S_ID" />
                                <generated-value strategy="SEQUENCE" 
generator="seqGen1" />
                                <sequence-generator name="seqGen1"      
sequence-name="SEQ_OBJECT_ID" />
                        </id>
                        
                        <basic name="name" />

                </attributes>
        </entity>


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