When an entity class uses property access by placing annotations on getter and setter methods, both a getter method and a setter method must be defined for a field to be persisted. Annotated getter methods that are not accompanied by a setter method are ignored by OpenJPA, whereas in this situation EclipseLink throws an exception.
This rule flags annotated getter methods for property access fields that are missing a setter method. Review the entity definition and modify it to behave as intended. If you want the field to be ignored by the JPA provider, remove any annotations on the getter method. If you want the field to be persisted, add a setter method.
In the following entity class, the getVersion method is flagged by the rule.
package entities; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Transient; import javax.persistence.Version; @Entity public class MissingSetter2 { private int id; private long time; public MissingSetter2 (int id) { this.id = id; } @Id public int getId() { return id; } public void setId(int id) { this.id = id; } // This getter is not annotated, so it is not flagged. public long getTime() { return time; } // This getter is flagged because it is annotated and there is no setter. @Version public double getVersion() { return 2.0; } public MissingSetter2() { time = 0; } } |
For information about this issue and other OpenJPA to EclipseLink migration issues, see the OpenJPA to EclipseLink JPA Migration: Mappings guide.