Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我看到这个@javax.persistence.Access(javax.persistence.AccessType.FIELD)是一个实体。这是什么意思?是否真的需要为实体声明 @Access 这个。
不,这不是必需的,但可能很有用。@Access用于指定 JPA 必须如何访问(获取和设置)实体的映射属性。如果访问类型设置为 FIELD,值将直接在字段上读取/设置,绕过 getter 和 setter。如果设置为 PROPERTY,则 getter 和 setter 用于访问字段值。
@Access
默认情况下(至少在 Hibernate 中),如果@Id注解在字段上,则使用 FIELD,如果 @Id 注解在 getter 上,则使用 PROPERTY。
@Id