This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

HibernateDaoSupport - BeanNameAutoProxyCreator - ClassCast Exception

I am trying a simple logging interceptor for a bean which extends HibernateDaoSupport..When i try to do getBean and cast it to my bean, i get java.lang.ClassCastException: $Proxy4..

if i remove extends from HibernateDaoSupport, aspect with BeanNameAutoProxyCreator works fine and if remove BeanNameAutoProxyCreator aspect, just the dao and hibernate works fine..it only fails if i extend hibernatedaosupport and apply beannameautoproxy aspect..

Comment

it works fine if i have an interface...i have existing project which has developed classes...so i wanted to use BeanNameAutoProxyCreator so that i dont need to define interfaces for all these classes..

Comment

thanks for the reply...will there be performance hit if i use BeanNameAutoProxyCreator with <property name="proxyTargetClass" value="true" />..or do i need to define interfaces for all classes that dont have it and not use proxyargeClass to true for better performance..

Comment

thanks for the reply...will there be performance hit if i use BeanNameAutoProxyCreator with <property name="proxyTargetClass" value="true" />..or do i need to define interfaces for all classes that dont have it and not use proxyargeClass to true for better performance..

There is a slight performance difference between JDK dynamic proxying and CGLIB proxying. And this difference fluctuates with each JDK release. So the exact loss/gain would depend on your JDK version. I have not noticed any "visible" performance losses myself but you may want to test it out for your application.

I did some stupidly trivial performance tests on my old blog (http://blogs.warwick.ac.uk/colinyates/) which essentially created 10000 instances of a class and then performed 10000 calls on a method.

It timed this for a class, a class extended by CGLIB and a class wrapped in a JDK proxy. The stats were that the 10000x10000 native calls took something like 37ms, the CGLIB took 200ms and the JDK (1.5_05) proxy took 700ms. I did the same thing on the latest JDK (1.5_07) and the proxy calls took about the same time as the CGLIB.

I cannot link to the original article because the blog system is currently down