These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: How to disable CGLIB enhanced class files?
PostPosted: Fri Feb 24, 2006 9:33 pm 
Newbie

Joined: Thu May 05, 2005 6:27 pm
Posts: 7
We have a rather large collection of persistent classes. Building the
session factory takes one minute, and it looks like most of the CPU
time is spent by CGLIB generating proxy classes.

So, I'd like to try reflection instead. I've added the following
hibernate property:
hibernate.cglib.use_reflection_optimizer=false

I've also created a mapping for a persistent class:
<class name="sandbox.TaskImpl" ... proxy="sandbox.Task" ... />

where TaskImpl is a class and Task is an interface.

When I use session.load(TaskImpl.class, new Integer(...)) to
get a lazy loaded object, I expected a Java Proxy class. However,
when I print out the class name of the returned object, I get this:
org.hibernate.proxy.HibernateProxy$$EnhancerByCGLIB$$b265b08a

I get the same result when I use use_reflection_optimizer=true.

I also have the followong properties set:
hibernate.current_session_context_class=thread
hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider
hibernate.show_sql=true
hibernate.cglib.use_reflection_optimizer=false
hibernate.jdbc.batch_size=5
hibernate.jdbc.batch_versioned_data=true
hibernate.jdbc.factory_class=sandbox.OracleBatcherFactory

When I remove the last two, the proxy class used is different:
sandbox.Task$$EnhancerByCGLIB$$7caee4d2

However, the result is the same, no matter what value I use for
use_reflection_optimizer.

I assumed that I should get a class generated by
java.lang.reflect.Proxy, called "$Proxy1" or similar.

I have no idea why OracleBatcher would effect the proxy classes,
it's a simple class that extends AbstractBatcher to use
getUpdateCount() of a PreparedStatement to check for stale
data.

So, what exactly do I need to do to disable CGLIB?

For large projects it would be nice to generate the proxy
classes first instead of dynamically creating them when
initializing the session factory. It's a bit annoying having to wait
more than one minute for the server to accept connections (at
least for development).


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 25, 2006 6:00 pm 
Regular
Regular

Joined: Mon Jun 13, 2005 12:21 pm
Posts: 61
Location: Hannover
Hi gabara,

the answer to you're question is short and propably not the one one you want to hear: You just cannot. There is no way disabling to cglib class.
Class enhancement with cglib is one of the fundamental principals of hibernate and it cannot work without it. The main reason for this is, java.lang.reflect.Proxy cannot deal with class but only with interface types.

If I understand you correct, you're actual problem is not cglib type but the startup time of you're application. A time of more than one minute for configuration seems in deep pretty long, how many mapped classes are in you're application? Configuration takes time, cause of the checks hibernate performs on startup. Have you done a performance measurement, or how did you get the information most time is spent with cglib on startup? Maybe there is some other solution for you're problem. Could you use a subgroup of you're mapping types for testing?

Joerg


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 27, 2006 3:48 pm 
Newbie

Joined: Thu May 05, 2005 6:27 pm
Posts: 7
Hi Joerg,

> The main reason for this is, java.lang.reflect.Proxy cannot deal
> with class but only with interface types.

Yes, I'm aware of that, that's why I've specified an interface to the
"proxy" attribute of the class mapping.

Right, the main problem we have is that Hibernate takes 1 minute
to build the session factory. I've ran YourKit CPU sampling during
this time, which shows that most of the time is spent by CGLIB
creating proxies. We have about 220 persistent classes.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.