openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Xiaoqin Feng (JIRA)" <j...@apache.org>
Subject [jira] Updated: (OPENJPA-722) persist - clear - merge scenario doesn't work
Date Thu, 18 Sep 2008 20:42:44 GMT

     [ https://issues.apache.org/jira/browse/OPENJPA-722?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Xiaoqin Feng updated OPENJPA-722:
---------------------------------

    Attachment: openjpa-722-fromQin.patch

Here are some clarifications for the code change. Jeremy, please review it and let me know
your opinion.
I don't have permission to submit to SVN yet. If you have, could you submit tit after it is
finalized? Thanks.

1. Added _flushBeforeDetach flag in Broker for EntityManagerImpl.clear(). 
This has same effect as setting openjpa.Compatibility property but it is used internally.
Added getter and setter in Broker interface. 

2. Save PCState and dirty flags with detached object if it is not flushed. 
See change in DetachManager.getDetachedState(StateManagerImpl, BitSet). 
Before my change, it made state object array one size longer but empty in that positon if
isNew.
Now I put PCState there if it is not flushed.
I don't know if the previous trick is used somewhere later at attach stage. At least in openjpa,
I didn't see it.
And all openjpa tests passed.

3. Use saved PCState and dirty flags to restore StateManager and other state during attachment.
See change in DetachedStateManager.attach().
For delete case, BrokerImpl.copy(OpenJPAStateManager copy, PCState state) could find StateManager
with same OID in cache 
so it doesn't set the new state with detached state. 
I changed StateManagerImpl.setPCState(PCState state) from private to protected so BrokerImpl
could set it.
I think this change is fine but just highlight for review.

> persist - clear - merge scenario doesn't work
> ---------------------------------------------
>
>                 Key: OPENJPA-722
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-722
>             Project: OpenJPA
>          Issue Type: Sub-task
>          Components: kernel
>    Affects Versions: 1.0.3, 1.1.0, 1.2.0
>            Reporter: Xiaoqin Feng
>            Assignee: Jeremy Bauer
>         Attachments: openjpa-722-fromQin.patch, TestEntityManagerClear-V2.java, TestEntityManagerClear.java
>
>
> EntityManager.clear() now don't  flush new object but only detach it.
> But DetachManager still flush dirty object and assume detached objects are in clean state.
> When the "new" object is merged back and transaction commit,  because the object state
lost its original state PNEW, it will not be added to insert list  and not flushed to DB.
> According to the EntityManager.clear() API,  changes made to entities that have not been
flushed to the database will not be persisted.  When they merges back to persistent context,
they all should kept there original state.
> I added the following test to org.apache.openjpa.persistence.simple.TestEntityManagerClear.
>     public void testClearMerge() {
>         // Create EntityManager and Start a transaction (1)
>         begin();
>         // Insert a new object then clear persistent context
>         AllFieldTypes testObject1 = new AllFieldTypes();
>         testObject1.setStringField("my test object1");
>         persist(testObject1);
>         //Object1 is not flushed to DB but only detached by clear().
>         em.clear();
>         em.merge(testObject1);
>         //expect the PCState is same as before detached, 
>         //so it is PNew instead of PCLEAN and is add to insert list.
>         commit();
>         
>         //Start a new transaction
>         begin();
>         
>         // Attempt retrieve of Object1 from previous PC (should exist)
>         assertEquals(1, query("select x from AllFieldTypes x "
>             + "where x.stringField = 'my test object1'").
>                 getResultList().size());
>         
>         // Rollback the transaction and close everything
>         rollback();
>     }

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


Mime
View raw message