سؤال

I'm using optimistic locking in my persistence context and trying to figure out a way to avoid write locking entity by updates to some entity fields.

Here's an example:

@Entity
public class A {
    private String field1;
    private String field2;

    @Version
    private long version;
}

So what I need is to avoid write locks (i.e. increment of a version field at the end of transaction) to the entity when updating field2, but still to have the default behavior on updates of any other entity field.

The solution I've figured out so far is to create my own versioning strategy (extend NumberVersionStrategy in case of example) to avoid incrementing entity's version if only specified fields were updated (only field2 in the example above). But this solution looks quite complex to me... Isn't there a special annotation for a field to exclude it from entity versioning or something? )

هل كانت مفيدة؟

المحلول

No, there is not a OpenJPA feature that allows you to exclude a given field from optimistic locking.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top