[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] EclipseLink 1.1.3: object persisted is not considered registered at commit time
|
My guess as to what is occurring is you call merge() on an existing object
that has a reference to this new object, so a copy of the new object is
registered by merge. Then when you try to persist it, it fails, as a
different copy is already persisted. The reason is, is the persist is
in-place (same object) and merge always creates a copy. You are probably
better always calling merge() for detached objects, not using persist.
If you are still having issues, it would be best if you could recreate your
issue in a simplified example, with the exact steps you do to get the error.
Mike Kienenberger wrote:
>
> I am using the EclipseLink 1.1.3, specifically the
> eclipselink-1.1.3.v20091002-r5404.zip distribution.
>
> I have a disconnected set of new and existing objects that I want to
> reattach to a clear()ed persistence manager via persist() or merge()
> as appropriate, and then commit(). Basically, we have our own simple
> JPA-API-based unit of work implementation which tracks changes to
> disconnected objects and then reattaches and commits those objects at
> an commit time.
>
> This methodology has worked fine in the past for similar situations,
> but today I'm hitting a problem where a new object which was
> persist()ed is being flagged as unpersisted in
> discoverAndPersistUnregisteredNewObjects() during commit().
>
> java.lang.IllegalStateException: During synchronization a new object
> was found through a relationship that was not marked cascade PERSIST:
> [toString() representation of my entity].
>
> Thread [btpool0-3] (Suspended (exception IllegalStateException))
>
> RepeatableWriteUnitOfWork(UnitOfWorkImpl).discoverAndPersistUnregisteredNewObjects(Object,
> boolean, Map, Map, Map) line: 4010
>
> OneToOneMapping(ObjectReferenceMapping).cascadeDiscoverAndPersistUnregisteredNewObjects(Object,
> Map, Map, Map, UnitOfWorkImpl) line: 743
> ObjectBuilder.cascadeDiscoverAndPersistUnregisteredNewObjects(Object,
> Map, Map, Map, UnitOfWorkImpl) line: 1511
>
> RepeatableWriteUnitOfWork(UnitOfWorkImpl).discoverAndPersistUnregisteredNewObjects(Object,
> boolean, Map, Map, Map) line: 4013
> RepeatableWriteUnitOfWork.discoverUnregisteredNewObjects(Map, Map,
> Map, Map) line: 206
> RepeatableWriteUnitOfWork(UnitOfWorkImpl).calculateChanges(Map,
> UnitOfWorkChangeSet, boolean) line: 628
>
> RepeatableWriteUnitOfWork(UnitOfWorkImpl).commitToDatabaseWithChangeSet(boolean)
> line: 1387
> RepeatableWriteUnitOfWork.commitRootUnitOfWork() line: 181
> RepeatableWriteUnitOfWork(UnitOfWorkImpl).commitAndResume() line: 1060
> EntityTransactionImpl.commitInternal() line: 84
> EntityTransactionImpl.commit() line: 63
>
> This is the behavior I am seeing. When I call persist() with this
> specific object instance and trace through the code to
> RepeatableWriteUnitOfWork(UnitOfWorkImpl).checkIfAlreadyRegistered, I
> see that a copy of the object is already considered registered,
> although not the specific instance I'm working with. [id instance
> values shown from the eclipse debugger]
>
> Argument:
> dataEntity = com.gvea.applications.cis.entity.jpa.JpaReceiptSource
> (id=2510)
>
>
>
> RepeatableWriteUnitOfWork(UnitOfWorkImpl).checkIfAlreadyRegistered(Object,
> ClassDescriptor) line: 765
>
> RepeatableWriteUnitOfWork(UnitOfWorkImpl).registerNewObjectForPersist(Object,
> Map) line: 4039
> EntityManagerImpl.persist(Object) line: 255
>
> if (hasNewObjects()) {
> registeredObject = getNewObjectsOriginalToClone().get(object);
>
> Values after checking getNewObjectsOriginalToClone() map:
>
> this =
> org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork
> (id=2859)
> object = com.gvea.applications.cis.entity.jpa.JpaReceiptSource
> (id=2510)
> registeredObject =
> com.gvea.applications.cis.entity.jpa.JpaReceiptSource (id=2868)
>
> As you can see, the copy (id=2868) is detected as registered, not the
> original object being persisted.
>
> But then when I go to commit(), I get the above IllegalStateException
> for (id=2510) since the code appears to only check getCloneMapping()
> and not getNewObjectsOriginalToClone() like the persist method does.
> [stack trace above]
>
> if (!isObjectRegistered(object)) {
> [...]
> } else {
> // It is new but not referenced by a cascade persist
> mapping, throw an error.
> throw new
> IllegalStateException(ExceptionLocalization.buildMessage("new_object_found_during_commit",
> new Object[]{object}));
> }
>
> this = org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork
> (id=2859)
> object = com.gvea.applications.cis.entity.jpa.JpaReceiptSource (id=2510)
>
>
-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland
http://www.eclipse.org/eclipselink/
EclipseLink , http://www.oracle.com/technology/products/ias/toplink/
TopLink
Wiki: http://wiki.eclipse.org/EclipseLink EclipseLink ,
http://wiki.oracle.com/page/TopLink TopLink
Forums: http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink ,
http://www.nabble.com/EclipseLink-f26430.html EclipseLink
Book: http://en.wikibooks.org/wiki/Java_Persistence Java Persistence
--
View this message in context: http://old.nabble.com/EclipseLink-1.1.3%3A-object-persisted-is-not-considered-registered-at-commit-time-tp26399269p26497987.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.