Help

Kind of knew people would ask about this... So why did we decide to deprecate CGLIB support in Hibernate? First I want to point out that Hibernate and CGLIB have a very long history (and a largely good history) in terms of working together. This is not an indictment against any of the CGLIB developers. They are good guys and as I stated above for many years Hibernate and CGLIB have worked well together.

The simple fact of the matter is that development on CGLIB has largely stopped. It happens. Developers for whatever reason (the reasons are their own) move on to new priorities.

The fact that development on CGLIB had even slowed initially came to my attention about 4 years ago in regards to HHH-2222. The problem described in the JIRA issue itself was not the concern; the concern was that the fix was simply a release of CGLIB 2.2 using the updated ASM library. That 2.2 release was over a year in coming.

More recently we have had issues with CGLIB in regards to signed jars as well as its handling of bytecode enhancement for annotated entities. The Hibernate team have submitted patches (to the best of our ability) to CGLIB for each of these issues we have found without even a response.

So it really comes down to a decision as to whether we want to get into maintaining a fork of CGLIB for Hibernate where we can fix stuff as we need. But that is not our core competency and we already have integration with another great bytecode library in Javassist. So I decided it was just time to move on.

BytecodeProvder, as an SPI, will remain intact so users are free to continue to use CGLIB as the bytecode provider for Hibernate. We just will not maintain the integration anymore.

6 comments:
 
20. Aug 2010, 12:05 CET | Link
Xevi

Hi,

We use CGLIB in our company to generate dinamyc proxy's for classes that aren't interfaces. We use the class net.sf.cglib.proxy.MethodInterceptor.

One reason to choose CGLIB was that Hibernate was using it. We evaluated use ASM directly but we feel it was very difficult to understant.

We have code fragments like this one:

       private class MyHelloWorldProxy implements MethodInterceptor
        {
                @Override
                public Object intercept(Object arg0, Method method, Object[] args, MethodProxy arg3) throws Throwable
                {
                        System.out.println("Hello world ...");
                        return null;
                }
        }

        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(method.getReturnType());
        enhancer.setCallback(new MyHelloWorldProxy 

        Object wObjPK = enhancer.create();

It is just a Method Interceptor that intercepts all method, say 'Hello World' and always return NULL.

This can be done using Javassist? There is any Hello World example like this one?

Thanks a lot.

Xevi.

 
20. Aug 2010, 16:00 CET | Link
Christopher Flather | chris.flather(AT)gmail.com

This code snippet should be roughly equivalent in Javassist:

private class MyHelloWorldProxy implements MethodHandler {
     public Object invoke(Object self, Method method, Method proceed, Object[] args) {
          System.out.println("Hello world ...");
          return null;
     }
}

ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setSuperclass(method.getReturnType());
Class<?> proxyClass = proxyFactory.createClass();

Object wObjPK = proxyClass.newInstance();
((ProxyObject) wObjPK).setHandler(new MyHelloWorldProxy());

There is a fantastic tutorial for JavaScript at: http://www.csg.is.titech.ac.jp/~chiba/javassist/tutorial/tutorial.html

 
20. Aug 2010, 16:04 CET | Link
Christopher Flather

The method signature should be:

public Object invoke(Object self, Method method, Method proceed, Object[] args) throws Throwable

and not:

public Object invoke(Object self, Method method, Method proceed, Object[] args)
 
20. Aug 2010, 17:09 CET | Link

Thanks for that Christopher!

 
20. Aug 2010, 17:11 CET | Link

Specializations can choose to not throw exceptions declared by their super/interface. But thanks for the correction for illustration purposes.

 
03. Apr 2014, 11:15 CET | Link

More recently we have had issues with CGLIB in regards to signed jars as well as its handling of bytecode enhancement for annotated entities. The Hibernate team have submitted patches (to the best of our ability) to CGLIB for each of these issues we have found without even a response.