English 中文(简体)
Parent with cascaded VersionLockingPolicy not picking up database changes to private owned child objects
原标题:

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?

最佳回答

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.

问题回答

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





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签