Hi,
I am getting this error when I add a @Transactional annotation to my DAO class:
When I remove @Transactional there is no error.Code:Caused by: java.lang.IllegalArgumentException: Can not set xxx.DAOHibernateImpl field xxx.DAOHibernateImpl.userDAO to $Proxy20
My applicationContext is as follows:
Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd "> <!-- autodetect these classes and register the corresponding beans --> <context:component-scan base-package="com.accounts" /> <!-- tells Spring annotations are used --> <context:annotation-config /> <!-- DATABASE STUFF --> <!-- This defines a Hibernate Session Factory. This Hibernate Session holds objects that it manages while they are in use. A list of annotated classes must be given to the Session Factory. The datasource defined above is used for this session. Finally, the hibernate.dialect property is set to the MySQL dialect. --> <bean id="sessionFactory" name="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" destroy-method="destroy"> <property name="annotatedClasses"> <list> <value>com.accounts.client.domain.BankAccount</value> <value>com.accounts.client.domain.BankTransaction</value> <value>com.accounts.client.domain.Purchase</value> <value>com.accounts.client.domain.Sale</value> <value>com.accounts.client.domain.User</value> </list> </property> <property name="dataSource" ref="dataSource" /> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop> <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory </prop> </props> </property> </bean> <!-- The datasource bean tells Spring how to connect to MySQL. There is a driver name, the username and password, a JDBC URL to the accounts database and an initial, max, and idle connection pool size. The Pool is managed by dbcp's BasicDataSource from our Maven Dependencies declarations. --> <bean id="dataSource" name="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName"> <value>com.mysql.jdbc.Driver</value> </property> <property name="url"> <value>jdbc:mysql://localhost:3306/accounts</value> </property> <property name="username"> <value>root</value> </property> <property name="password"> <value></value> </property> <property name="initialSize"> <value>2</value> </property> <property name="maxActive"> <value>5</value> </property> <property name="maxIdle"> <value>2</value> </property> </bean> <!-- The Transaction Manager is needed to track the start and end of database transactions. Spring comes with its own transaction manager specifically for Hibernate. --> <!-- TRANSACTION MANAGER --> <bean id="transactionManager" name="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- Here we tell Spring that we are going to manage Transactions through annotations (and we will have a @Transactional annotation in this project, so we need this). --> <!-- ANNOTATION DRIVEN TRANSACTIONS --> <tx:annotation-driven transaction-manager="transactionManager" /> </beans>
An example DAO class is:
Any help would be greatly appreciated.Code:@Repository("baseObjectDAOHibernateImpl") public class BaseObjectDAOHibernateImpl implements BaseObjectDAO { private static final Log log = LogFactory .getLog(BaseObjectDAOHibernateImpl.class); @Autowired @Qualifier("sessionFactory") public SessionFactory sessionFactory; public BaseObject save(BaseObject baseObject) { log.debug("persisting one instance of baseobject"); try { sessionFactory.getCurrentSession().saveOrUpdate( baseObject); log.debug("persist one instance successful"); } catch (RuntimeException re) { log.error("persist one instance failed", re); throw re; } return baseObject; }


Reply With Quote