I am getting a strange exception when trying to configure annotated JPA transactions. Running in Tomcat, Spring 2.5.4, Hibernate 3.2.5, cglib 2.2
My context:
class that's blowing up on startup:Code:<tx:annotation-driven transaction-manager="transactionManager"/> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"/> <property name="dataSource" ref="dataSource"/> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="persistenceUnitName" value="p1" /> <property name="dataSource" ref="dataSource" /> <property name="persistenceXmlLocation" value="classpath:persistence.xml" /> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="showSql" value="true" /> <property name="generateDdl" value="true" /> <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" /> </bean> </property> </bean>
Code:Transactional @Repository public abstract class BaseDao<T extends Serializable, K extends Serializable> { @PersistenceContext protected EntityManager entityMgr; private Class<T> tClass; @SuppressWarnings("unchecked") protected BaseDao(){ this.entityMgr = null; log.debug("*** genericSuperclass(): " + getClass().getGenericSuperclass()); this.tClass = (Class<T>) ((ParameterizedType) getClass() .getGenericSuperclass()).getActualTypeArguments()[0]; } }
And the exception:
No idea why the constructor is called twice. If I remove the <tx:annotation-driven/>, spring has no problem loading... but i get no transaction mangement with out it. You can see the debug being called twice, and only when <tx:annotation-driven> is present in config.Code:2008-06-19 23:31:52,484 DEBUG [net.mycompany.dao.BaseDao] - <*** genericSuperclass(): net.mycompany.dao.BaseDao<net.mycompany.pm.Address, java.lang.Long>> 2008-06-19 23:31:52,796 DEBUG [net.mycompany.dao.BaseDao] - <*** genericSuperclass(): class net.mycompany.dao.AddressDAO> 2008-06-19 23:31:52,937 INFO [org.hibernate.impl.SessionFactoryImpl] - <closing> 2008-06-19 23:31:52,953 ERROR [org.springframework.web.context.ContextLoader] - <Context initialization failed> org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'addressDAO' defined in ServletContext resource [/WEB-INF/classes/hibernateSpringContext.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class net.mycompany.dao.AddressDAO]: Common causes of this problem include using a final class or a non-visible class; nested exception is net.sf.cglib.core.CodeGenerationException: java.lang.ClassCastException-->java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:478) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:220) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764)
I have not found anyone else experiencing the same problem. Any clue as to what it means?
Help, please.


Reply With Quote