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