I saw this @javax.persistence.Access(javax.persistence.AccessType.FIELD) for a Entity. What does this mean? Is it really required to declare @Access this for a entity.
Asked
Active
Viewed 7,738 times
9
-
Maybe this helps: http://stackoverflow.com/questions/13874528/what-is-the-purpose-of-accesstype-field-accesstype-property-and-access – RubberPoach Oct 09 '13 at 06:57
1 Answers
17
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.

JB Nizet
- 678,734
- 91
- 1,224
- 1,255