How to force Hibernate 3.3 or 3.5 to use CGLib instead of Javassist?
Solution 1
It seems some people didn't read my answer correctly so I'll rephrase: your hibernate.properties
looks correct, the property is well defined, it should work. So, sorry for the question but is CGlib on the classpath?
Update: Just tested and it works for me. Here is the output I get at initialization time:
15 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.0.SP1 18 [main] INFO org.hibernate.cfg.Environment - loaded properties from resource hibernate.properties: {hibernate.bytecode.use_reflection_optimizer=false, hibernate.bytecode.provider=cglib} 20 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : cglib
PS: Note that CGLIB support has been deprecated recently (this doesn't mean you won't be able to use CGLIB but the integration it not maintained anymore).
Solution 2
Yeah, also put
hibernate.properties
into some source folder and remember to have the hibermate-cglib-repack in dependencies:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-cglib-repack</artifactId>
<version>2.1_3</version>
</dependency>
Solution 3
Remember that CGLIB library is not developed for about 4 years. You should do everything however to make your code working with Javassist, which is still actively maintained.
mshafrir
Languages: Ruby, Python, Java, Javascript, Coffeescript, C#
Updated on June 18, 2022Comments
-
mshafrir almost 2 years
Is it still possible to force Hibernate 3.3 or 3.5 to use CGLib instead of Javassist? In my properties file, I set
hibernate.bytecode.provider = cglib
But this doesn't seem to do it. Any thoughts?
-
dma_k over 13 yearsStarting from Hibernate 3.3.2 the repackaged version of cglib is not needed. And, at least for 3.2.x, on need to speiofy either
-Dhibernate.bytecode.provider=cglib
system property or to create a classpath-widehibernate.properties
with the same property defined. -
dma_k over 13 yearsI don't know how it works in your environment (maybe you are running Hibernate packaged with JBoss?), but Hibernate needs a system property or a
hibernate.properties
in classpath on class creation (stupid!) to capture the bytecode provider setting. So havingcglib
in classpath is not a root of the issue. Both 3.3.1 and 3.3.2 do not work "out of he box". -
Devanshu Mevada over 13 years@dma_k Read the question again, the OP does have a
hibernate.properties
file ("In my properties file, I set") on the classpath, so this part is implied by my answer ("and your property is well defined"). Maybe you misunderstood what the OP and I said, in which case, I ask you to reconsider your vote. I never said the property file was not needed. -
Devanshu Mevada over 13 years@dma_k The log trace even illustrates that I have a
hibernate.properties
. You totally misread what I said. -
dma_k over 13 yearsOh, yea, I missed that. Sorry for fuzz. +1