Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » merge does not copy basic mappings
merge does not copy basic mappings [message #387024] Tue, 07 April 2009 14:51 Go to next message
Joerg Koldehoff is currently offline Joerg KoldehoffFriend
Messages: 3
Registered: July 2009
Junior Member
Hi !

I have a problem with the merge since 1.1.0.r3634. The merge of the
entityManager seems not to merge primitives attributes like long datatypes.
My source code looks like:

Entity entity = new Entity();
entity.setAId(1000);
...
Entity mergedEntity = em.merge(en);

Now the aId value of the mergedEntity is null. In the previous 1.0.1
release the primitive attributes were copied.

I looked at the source code of the ObjectBuilder.mergeIntoObject(Object
target, boolean isUnInitialized, Object source, MergeManager mergeManager,
boolean cascadeOnly, boolean isTargetCloneOfOriginal) method, that is part
of the merge logic.

The source code looks a bit strange, because the isTargetCloneOfOriginal
will doesn't take any effect. I think there is a problem in the boolean
logic.

// PERF: Avoid synchronized enumerator as is concurrency bottleneck.
List mappings = this.descriptor.getMappings();
for (int index = 0; index < mappings.size(); index++) {
DatabaseMapping mapping = (DatabaseMapping)mappings.get(index);
if ((!cascadeOnly && !isTargetCloneOfOriginal)
|| (cascadeOnly && mapping.isForeignReferenceMapping())
|| (isTargetCloneOfOriginal && mapping.isCloningRequired())) {
mapping.mergeIntoObject(target, isUnInitialized, source,
mergeManager);
} else if (isTargetCloneOfOriginal && mapping.isCloningRequired()) {
mapping.mergeIntoObject(target, isUnInitialized, source,
mergeManager);
}
}

For me the second "else if" doesn't make sense, because it will never be
reached. The same expression is in the first if statement, so this will be
executed first. Perhaps there was forgotten to negate the
isTargetCloneOfOriginal Boolean in the second if statement ?

Does anyboday agree with that?
Re: merge does not copy basic mappings [message #387026 is a reply to message #387024] Tue, 07 April 2009 20:40 Go to previous messageGo to next message
Gordon Yorke is currently offline Gordon YorkeFriend
Messages: 77
Registered: July 2009
Member
I have attempted to reproduce this error and I can not. We also have
tests in our Regression testing that tests this functionality and continue
to pass. Are you sure that you are looking at the managed object? Are
you sure you are merging the object that you expect to be merging? Can
you provide a simple testcase?

The method you referenced to does seem to have a simple error. The else
if should be removed.
--Gordon
Re: merge does not copy basic mappings [message #387035 is a reply to message #387026] Wed, 08 April 2009 16:12 Go to previous messageGo to next message
Joerg Koldehoff is currently offline Joerg KoldehoffFriend
Messages: 3
Registered: July 2009
Junior Member
Hi Gordon !

I wrote a testcase. This testcase was successfull under 1.0.1 but not
successfull under 1.1.

@Test
public void testMerge() {

deleteFromTables("M_HIST_B");

HistB b = new HistB();
b.setValidFrom(new Date());
b.setVersion(1);
b.setName("B");

HistB managedB = (HistB)em.merge(b);

b = new HistB();
b.setId(managedB.getId());
b.setValidFrom(managedB.getValidFrom());
b.setVersion(managedB.getVersion());
b.setName("CHANGED");

HistB managedB2 = (HistB)em.merge(b);

Assert.assertEquals("CHANGED", managedB2.getName());
}

HistB is a JPA Entity with a compound key (id, validFrom, version). The id
is generated by a sequence.

I think there is be a problem when the merge find an entity in the cache.
In this case the primitive attributes are not copied in the merged entity.
Re: merge does not copy basic mappings [message #387066 is a reply to message #387035] Thu, 09 April 2009 13:27 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Thanks for isolating this. The bug occurs when a new object is merged
twice in the same transaction. Please log a bug for this and include you
test.

The bug is in MergeManager.mergeChangesOfCloneIntoWorkingCopy() as it uses
a cascadeOnly merge if the object is new.

I think a workaround would be to flush after the first merge.

---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Re: merge does not copy basic mappings [message #387074 is a reply to message #387066] Thu, 09 April 2009 19:21 Go to previous message
Joerg Koldehoff is currently offline Joerg KoldehoffFriend
Messages: 3
Registered: July 2009
Junior Member
Ok, i opened a bug with the id 271836.
Previous Topic:escaping table names
Next Topic:Is JPA QL supposed to be this picky?
Goto Forum:
  


Current Time: Thu Nov 27 11:02:16 GMT 2014

Powered by FUDForum. Page generated in 0.03534 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software