According to the JPA 2.1 specification, when property access is used, the property accessor methods must be public or protected. OpenJPA ignores any private accessor methods, whereas EclipseLink persists those attributes. To ignore private accessor methods in EclipseLink, the methods must have a Transient annotation.
This rule flags private accessor getter methods. The quick fix for this rule adds the
javax.persistence.Transient annotation to the method so that the application
has the same behavior in EclipseLink as it does with OpenJPA.
To persist the attribute, do not run the quick fix and instead change the private access control modifier to
public or protected.
For example, the rule flags the getNonPersistentField() method in the following entity class:
package entities; import javax.persistence.Entity; import javax.persistence.Id; @Entity public class PrivateAccessor { private int id; private int field; @Id public int getId() { return id; } public void setId(int id) { this.id = id; } private int getNonPersistentField() { return nonPersistentField; } private void setNonPersistentField(int value) { this.field = value; } } |
After the quick fix is run, the Transient annotation is applied
to the private accessor method, and the import is added.
package entities; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Transient; @Entity public class PrivateAccessor { private int id; private int field; @Id public int getId() { return id; } public void setId(int id) { this.id = id; } @Transient private int getNonPersistentField() { return nonPersistentField; } private void setNonPersistentField(int value) { this.field = value; } } |
For information about this issue and other OpenJPA to EclipseLink migration issues, see the OpenJPA to EclipseLink JPA Migration: Mappings guide.