views:

681

answers:

2

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?

+5  A: 

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).

Pascal Thivent
@Pascal Thivent: I 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 having `cglib` in classpath is not a root of the issue. Both 3.3.1 and 3.3.2 do not work "out of he box".
dma_k
@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.
Pascal Thivent
@dma_k The log trace even illustrates that I have a `hibernate.properties`. You totally misread what I said.
Pascal Thivent
@Pascal Thivent: Oh, yea, I missed that. Sorry for fuzz. +1
dma_k
+1  A: 

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> 
Martin
Starting 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-wide `hibernate.properties` with the same property defined.
dma_k