Problem installing byte code provider in sleep mode

I am trying to add cglib as the default byte code provider. I am using the hibernate.cfg.xml file to set up a factory session.

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

Above the line of code in my configuration file, no behavior changes occur. It still installs javassist as a javassist provider.

It turns out that "javaassist" is set as the default provider. This configuration is updated in the environment hibernate.properties form file. I did not find a reference to the bytecode code creator method anywhere except in the static initializer of the Environment class.

Is there any final way to assign a default byte generator from xml configuration files.

+4
source share
2 answers

Environment javadoc says:

Hibernate has two property areas:

  • Factory level properties can be passed to SessionFactory when it is created. Each instance can have different property values. If no properties are specified, the factory calls Environment.getProperties ().
  • The properties of the system level are shared by all instances of the factory and are always determined by the properties of the environment.

The only properties of the system level 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 one exists. System property properties override the properties specified in hibernate.properties.

However, this is not quite true. Looking at the source code, it becomes clear that hibernate.bytecode.provider also a system level property, so it cannot be specified in hibernate.cfg.xml , only in hibernate.properties .

+5
source

'hibernate.bytecode.provider' cannot be configured:

 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(); } 
+2
source

Source: https://habr.com/ru/post/1339459/


All Articles