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 of @Access on the class specifies the default access. When placed on a field or property getter @Access can specify that the default should be overridden for this field.
@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
}
}
This class should result in a table with three columns. 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.
Can anyone confirm this or did I make a stupid mistake somewhere?