bob-cac
bob-cac

Reputation: 1302

JPA attribute Override

Can we override attribute to stop versionning in the subclass given it is used in the super i am using eclipse link.

Class A {
@Version 
int a;
}

Class B extends A
{
//a is used as a normal integer not a version.
}

if it is not possible can we override the version Field a to be transient in B and remove it from B table.

Upvotes: 0

Views: 373

Answers (1)

Chris
Chris

Reputation: 21145

Versions seem to be considered fundamental to the entity, much like the ID does, so do not have a way to be overridden by subclasses. What you could do is mark it as using field locking on the 'a' attribute by using the @OptimisticLocking annotation and specify the selectedColumns: http://www.eclipse.org/eclipselink/documentation/2.4/jpa/extensions/a_optimisticlocking.htm This would allow you to control the value used. In A you might define a preupdate method that increments the value, while in B you can override the logic that increments it. This will still allow optimistic lock exceptions to occur when another transaction changes the value 'a' value, but it makes it an application controlled step.

Upvotes: 1

Related Questions