简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM