Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with setting byte code provider in hibernate application

Tags:

hibernate

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.

like image 610
Vijay Shanker Dubey Avatar asked Feb 25 '23 02:02

Vijay Shanker Dubey


1 Answers

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.

like image 161
axtavt Avatar answered May 26 '23 09:05

axtavt