我正在尝试将cglib添加为默认字节代码提供程序。我正在使用hibernate.cfg.xml
文件来配置会话工厂。
<property name="hibernate.bytecode.provider">cglib</property>
我的配置文件中的上面一行代码不会对行为进行任何更改。它仍然将javassist
设置为字节代码提供程序。
原来是'javaassist'被设置为默认提供者。此配置在环境表单hibernate.properties文件中更新。除了Environment类的静态初始化程序之外,我没有找到任何对字节代码提供程序创建者方法的引用。
是否有任何确定的方法从xml配置文件中分配默认字节代码生成器。
答案 0 :(得分:5)
Hibernate有两个属性范围:
- 工厂级属性可以在实例化时传递给SessionFactory。每个实例可能具有不同的属性值。如果未指定任何属性,则工厂将调用Environment.getProperties()。
- 系统级属性由所有工厂实例共享,并始终由Environment属性确定。
唯一的系统级属性是
- 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
中指定。
答案 1 :(得分:2)
&#39; hibernate.bytecode.provider&#39;不能自定义:
private static BytecodeProvider buildBytecodeProvider(String providerName) {
if ( "javassist".equals( providerName ) ) {
return new org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl();
}
LOG.unknownBytecodeProvider( providerName );
return new org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl();
}