Can anyone confirm this or did I make a stupid mistake somewhere?
According to my JPA 2.0 book (and online documentation), I should be able to mix field and property access within a single entity or entity hierarchy. The annotation
@Access on the class specifies the default access -- and when placed on a field or property getter it specifies that the default should be overridden for this one particular field. This class should result in a table with three columns:
Code:
@Entity
@Access(AccessType.FIELD)
Class Foo {
@Id
int id;
@Column(name = "myfield")
String myField;
@Column(name = "myProp")
@Access(AccessType.PROPERTY)
public int getMyProp () {
return 3;
}
public void setMyProp (int p) {
// do nothing
}
}
However it doesn't with Hibernate...the "myProp" column is missing from the table because apparently Hibernate takes its field vs property cue from the entity ID and runs with it...totally ignoring the JPA spec with regards to @Access.
Conversely, if I move the @Id annotation to a getter method, then the annotated field "myField" is ignored.