openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeremy Bauer (JIRA)" <j...@apache.org>
Subject [jira] Commented: (OPENJPA-714) "Encountered unmanaged object in persistent field" error while merging object tree
Date Fri, 05 Sep 2008 15:28:44 GMT

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

Jeremy Bauer commented on OPENJPA-714:
--------------------------------------

Adding my original response from the user mailing list (below) for documentation purposes.
 Arguably, I think OpenJPA is behaving within the spec, but it does seem like there should
be enough information to do the merge.  I have your test running and will take a more in-depth
look at this issue.

On Wed, Jul 9, 2008 at 7:52 PM, Jeremy Bauer <techhusky@gmail.com> wrote:

> I ran into a similar issue last week while using the merge operation.
> I found that since I had a bi-directional relationship with unmanaged
> entities (B <---> C in your case), OpenJPA needed both PERSIST and
> MERGE cascade enabled in order to maintain both sides of the
> relationship.  That way, new related entities can be persisted and
> existing entities can be merged from either side of the relationship.
> This behavior does not appear to be specifically defined by section
> 3.2.4.1 of the JPA spec, but it is also in my opinion, not
> contradictory to the requirements which are defined.  I could be
> totally off, but I was able to twist my own arm hard enough to
> convince myself that OpenJPA is working as expected.  :-)
>
> Besides adding adding the cascade options to C, if you make the B --->
> C relationship uni-directional or merge B (making it managed) before
> relating it to C (and vice-versa), the test also worked for me without
> problems.



> "Encountered unmanaged object in persistent field" error while merging object tree
> ----------------------------------------------------------------------------------
>
>                 Key: OPENJPA-714
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-714
>             Project: OpenJPA
>          Issue Type: Bug
>    Affects Versions: 1.1.0, 1.2.0
>         Environment: Fedora Linux 6
> java version "1.5.0_11"
>            Reporter: Ekin Sokmen
>         Attachments: testcase_jira714.zip
>
>
> I get following error while merging a persisted entity A after adding new child entities
to it.  The following relation exists between entities:  A -> (many to many) B -> (one
to many) C. If I add "cascade= {CascadeType.MERGE, CascadeType.PERSIST}" to ChainEntityC.chainEntityB
field It works.
> My opinion is the cascade type on entity C should not be necessary because C is the last
entity in the chain and should be cascaded from A to B to C. Cascade from C to B does not
sound logical. The information is already given using foreignkey and cascase annotation. 
> The test code is attached and works if you copy it to openjpa-persistence-jdbc test module.

> Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 3.62 sec <<<
FAILURE!
> testChainEntities(org.apache.openjpa.persistence.relations.TestChainEntities)  Time elapsed:
3.561 sec  <<< ERROR!
> <openjpa-1.1.0-r422266:659716 nonfatal user error> org.apache.openjpa.persistence.InvalidStateException:
Encountered unmanaged object in persistent field "org.apache.openjpa.persistence.relations.ChainEntityC.chainEntityB"
during flush.  However, this field does not allow cascade persist. Set the cascade attribute
for this field to CascadeType.PERSIST or CascadeType.ALL (JPA annotations) or "persist" or
"all" (JPA orm.xml), or enable cascade-persist globally, or manually persist the related field
value prior to flushing. You cannot flush unmanaged objects or graphs that have persistent
associations to unmanaged objects.
> FailedObject: org.apache.openjpa.persistence.relations.ChainEntityB@42a818
>         at org.apache.openjpa.kernel.SingleFieldManager.preFlushPC(SingleFieldManager.java:753)
>         at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:594)
>         at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:562)
>         at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:478)
>         at org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2819)
>         at org.apache.openjpa.kernel.PNewProvisionalState.nonprovisional(PNewProvisionalState.java:44)
>         at org.apache.openjpa.kernel.StateManagerImpl.nonprovisional(StateManagerImpl.java:1130)
>         at org.apache.openjpa.kernel.SingleFieldManager.preFlushPC(SingleFieldManager.java:772)
>         at org.apache.openjpa.kernel.SingleFieldManager.preFlushPCs(SingleFieldManager.java:735)
>         at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:637)
>         at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:562)
>         at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:478)
>         at org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2819)
>         at org.apache.openjpa.kernel.PNewProvisionalState.nonprovisional(PNewProvisionalState.java:44)
>         at org.apache.openjpa.kernel.StateManagerImpl.nonprovisional(StateManagerImpl.java:1130)
>         at org.apache.openjpa.kernel.SingleFieldManager.preFlushPC(SingleFieldManager.java:772)
>         at org.apache.openjpa.kernel.SingleFieldManager.preFlushPCs(SingleFieldManager.java:735)
>         at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:637)
>         at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:562)
>         at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:478)
>         at org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2819)
>         at org.apache.openjpa.kernel.PDirtyState.beforeFlush(PDirtyState.java:37)
>         at org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:957)
>         at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1945)
>         at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1905)
>         at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1823)
>         at org.apache.openjpa.kernel.LocalManagedRuntime.commit(LocalManagedRuntime.java:81)
>         at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1347)
>         at org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:877)
>         at org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:512)
>         at org.apache.openjpa.persistence.relations.TestChainEntities.chainUpdate(TestChainEntities.java:59)
>         at org.apache.openjpa.persistence.relations.TestChainEntities.testChainEntities(TestChainEntities.java:27)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:585)
>         at junit.framework.TestCase.runTest(TestCase.java:154)
>         at junit.framework.TestCase.runBare(TestCase.java:127)
>         at junit.framework.TestResult$1.protect(TestResult.java:106)
>         at junit.framework.TestResult.runProtected(TestResult.java:124)
>         at junit.framework.TestResult.run(TestResult.java:109)
>         at junit.framework.TestCase.run(TestCase.java:118)
>         at org.apache.openjpa.persistence.test.PersistenceTestCase.run(PersistenceTestCase.java:122)
>         at junit.framework.TestSuite.runTest(TestSuite.java:208)
>         at junit.framework.TestSuite.run(TestSuite.java:203)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:585)
>         at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
>         at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
>         at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
>         at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:585)
>         at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:334)
>         at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:980)
> Results :
> Tests in error:
>   testChainEntities(org.apache.openjpa.persistence.relations.TestChainEntities)
> Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

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