Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of the @Access annoation in JPA means at the Entity level?

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.

like image 672
Ramesh Avatar asked Oct 09 '13 06:10

Ramesh


1 Answers

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.

like image 196
JB Nizet Avatar answered Oct 27 '22 12:10

JB Nizet