Reputation: 165
I saw this @javax.persistence.Access(javax.persistence.AccessType.FIELD) for an Entity. What does this mean? Is it really required to declare @Access this for an entity?
Upvotes: 9
Views: 8595
Reputation: 691933
No, it's not required, but can be useful. @Access
is used to specify how JPA must access (get and set) mapped properties of the entity. If access type is set to FIELD, the values will directly be read/set on the field, bypassing getters and setters. If set to PROPERTY, the getters and setters are used to access the field value.
By default (at least with Hibernate), FIELD is used if the @Id
annotation is on a field, and PROPERTY is used if the @Id annotation is on a getter.
Upvotes: 18