在hibernate应用程序中设置字节码提供者的问题 [英] Problem with setting byte code provider in hibernate application

查看:102
本文介绍了在hibernate应用程序中设置字节码提供者的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图添加cglib作为默认的字节码提供者。我正在使用 hibernate.cfg.xml 文件来配置会话工厂。

 < property name =hibernate.bytecode.provider> cglib< / property> 

我的配置文件中的上面一行代码没有对行为做任何改变。它仍然将 javassist 设置为字节码提供程序。



事实证明'javaassist'被设置为默认供应商。此配置在Environment形式的hibernate.properties文件中更新。除了Environment类的静态初始化程序之外,我没有发现任何对字节码提供程序创建者方法的引用。



是否有任何明确的方式从xml配置文件中分配默认字节码生成器。 解决方案

Environment javadoc 说:


Hibernate有两个属性范围: / p>


  • 工厂级属性可以在实例化时传递给SessionFactory。每个实例可能具有不同的属性值。如果没有指定属性,工厂将调用Environment.getProperties()。

  • 系统级属性由所有工厂实例共享,并且始终由环境属性确定。



唯一的系统级属性是


  • hibernate.jdbc.use_streams_for_binary

  • hibernate.cglib.use_reflection_optimizer



环境属性已填充通过调用System.getProperties(),然后从名为/hibernate.properties的资源(如果存在)调用。系统属性覆盖hibernate.properties中指定的属性。


然而,这并不完全正确。查看源代码后,很明显, hibernate.bytecode.provider 也是一个系统级属性,因此它不能在中指定。 hibernate.cfg.xml ,仅限于 hibernate.properties


I am trying to add cglib as default byte code provider. I am using hibernate.cfg.xml file to configure session factory.

<property name="hibernate.bytecode.provider">cglib</property>

Above line of code in my configuration file does not make any change in the behavior. It still sets javassist as byte code provider.

It turns out to be 'javaassist' is set to be default provider. This configuration is updated in the Environment form hibernate.properties file. I did not find any reference to the byte code provider creator method anywhere other than the static initializer of the Environment class.

Is there any definitive way to assign default byte code generator form the xml configuration files.

解决方案

Environment javadoc says:

Hibernate has two property scopes:

  • Factory-level properties may be passed to the SessionFactory when it instantiated. Each instance might have different property values. If no properties are specified, the factory calls Environment.getProperties().
  • System-level properties are shared by all factory instances and are always determined by the Environment properties.

The only system-level properties are

  • hibernate.jdbc.use_streams_for_binary
  • hibernate.cglib.use_reflection_optimizer

Environment properties are populated by calling System.getProperties() and then from a resource named /hibernate.properties if it exists. System properties override properties specified in hibernate.properties.

However, it's not completely true. After looking at the source code it becomes clear that hibernate.bytecode.provider is a system-level property too, therefore it can't be specified in hibernate.cfg.xml, only in hibernate.properties.

这篇关于在hibernate应用程序中设置字节码提供者的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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