[英]Set Hibernate access strategy globally?
According to the Hibernate documentation , the placement of the @Id
annotation determines how Hibernate will access the entity (field or accessors)根据Hibernate 文档,@Id 注释的位置决定了
@Id
将如何访问实体(字段或访问器)
As a JPA provider, Hibernate can introspect both the entity attributes (instance fields) or the accessors (instance properties).
作为 JPA 提供者,Hibernate 可以自省实体属性(实例字段)或访问器(实例属性)。 By default, the placement of the @Id annotation gives the default access strategy.
默认情况下,@Id 注释的位置提供了默认访问策略。 When placed on a field, Hibernate will assume field-based access.
放置在字段上时,Hibernate 将采用基于字段的访问。 Place on the identifier getter, Hibernate will use property-based access.
放置在标识符 getter 上,Hibernate 将使用基于属性的访问。
Is it possible to define this globally via a property (To avoid having to place a @Access(AccessType.FIELD)
on each entity or embeddable)?是否可以通过属性全局定义它(为了避免必须在每个实体上放置
@Access(AccessType.FIELD)
或嵌入)?
I found this related question , but that is for Spring Boot specifically.我发现了这个相关的问题,但那是专门针对 Spring Boot 的。
You can create a file called orm.xml
and put it to the classpath in directory META-INF
.您可以创建一个名为
orm.xml
的文件并将其放入目录META-INF
中的类路径中。
In that file you can set default values.在该文件中,您可以设置默认值。 For example the access type:
例如访问类型:
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings>
<persistence-unit-metadata>
<access>PROPERTY</access>
</persistence-unit-metadata>
</entity-mappings>
You can find the XML Schema here: https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/resources/org/hibernate/jpa/orm_2_2.xsd You can find the XML Schema here: https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/resources/org/hibernate/jpa/orm_2_2.xsd
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.