Hibernate在整个Spring Boot应用程序上设置属性访问策略 [英] Hibernate set property access strategy on whole Spring Boot application

查看:59
本文介绍了Hibernate在整个Spring Boot应用程序上设置属性访问策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hibernate提供了两种访问策略:FIELD和PROPERTY.可以通过在实体上方设置注释 @Access 来定义它,但是每次在实施过程中使用策略设置 @Access 都会有些令人沮丧.有什么方法可以在整个应用程序上将访问策略设置为全局"吗?

as I know Hibernate provides two access strategy: FIELD and PROPERTY. It is possible to define it by setting anotation @Access above entity, but it is a little bit frustrating to set every time @Access with strategy during implementation. Is there any way to set access strategy "global" on the whole of application?

推荐答案

默认情况下,我认为Spring Boot中不存在这样的属性.

I don't think such a property exists in Spring Boot by default.

但是,您可以为所有实体创建一个父类,以在类级别一次定义 @AccessType .

However, you can create a parent class for all your entities to define @AccessType at the class level just once.

文档

2.3.1默认访问类型(第23页)

默认情况下,单一访问类型(字段或属性访问)适用于实体层次结构.实体层次结构的默认访问类型是由映射注释在属性上的位置确定实体层次结构的实体类和映射的超类不会明确指定访问类型.

By default, a single access type (field or property access) applies to an entity hierarchy. The default access type of an entity hierarchy is determined by the placement of mapping annotations on the attributes of the entity classes and mapped superclasses of the entity hierarchy that do not explicitly specify an access type.

示例

@MappedSuperclass
@Access(value=AccessType.FIELD)
public class Parent { 
}

@Entity
public class Child extends Parent {
    ...
}

这篇关于Hibernate在整个Spring Boot应用程序上设置属性访问策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆