Parent with cascaded VersionLockingPolicy not picking up database changes to private owned child objects

StackOverflow https://stackoverflow.com/questions/1764320

  •  21-09-2019
  •  | 
  •  

Question

I have a parent object with a version locking policy defined as follows:

VersionLockingPolicy lockingPolicy = new VersionLockingPolicy();
lockingPolicy.setIsCascaded(true);
lockingPolicy.setWriteLockFieldName("CacheId");
descriptor.setOptimisticLockingPolicy(lockingPolicy);

and with a child mapped as follows:

OneToManyMapping childMapping = new OneToManyMapping();
childMapping.setAttributeName("children");
childMapping.setReferenceClass(Child.class);
childMapping.dontUseIndirection();
childMapping.privateOwnedRelationship();
childMapping.useBatchReading();
childMapping.useCollectionClass(ArrayList.class);
childMapping.addTargetForeignKeyFieldName("Child.ParentId", "Parent.Id");
descriptor.addMapping(childMapping);

When I change a field on the child and update the child cacheId directly on the database, eclipselink queries do not pick up the change. When I then update the cacheId of the parent object, eclipselink queries do return the change to the child field.

I thought the cascaded version locking policy was supposed to cause the parent to update when any of its private owned child objects were updated (as defined by their version fields). Was I wrong about that, or is there likely something wrong somewhere else in my code?

Was it helpful?

Solution 2

I was wrong. There is nothing in the eclipselink code that will do what I wanted.

I think I will simply add a trigger to the child objects to update the parent cacheId.

OTHER TIPS

Just use the following on the parent entity class:

@OptimisticLocking(cascade = true)

and mark @OneToMany with @PrivateOwned

This works only if you use version column. Please check:

http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Using_EclipseLink_JPA_Extensions_for_Optimistic_Locking

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top