Hi,
I am trying to write a base class for integration testing. Unfortunately I can't extend the AbstractTransactionalSpringContextTest because I need to extend MockStrutsTestCase. So I decided to include the functionality in a base class which is essentially the same as AbstractTransactionalSpringContextTest.
I want to be able to provide a 'hibernateTemplate' to specific implementations to use for setup of Integration testing. In this manner I can setup the database state, run the test case and then roll-back the transaction within the base class.
I keep getting an IllegalTransactionStateException with the messageI've looked at the code and this exception is called ifPre-bound JDBC connection found - HibernateTransactionManager does not support running within DataSourceTransactionManager if told to manage the DataSource itself. It is recommended to use a single HibernateTransactionManager for all transactions on a single DataSource, no matter whether Hibernate or JDBC access.I am very confused by this error message and I was hoping someone could tell me what I am doing wrong. My appContext isif (getDataSource() != null && TransactionSynchronizationManager.hasResource(getD ataSource())) {I am using Declared Transactions using TransactionProxy when wiring up my real transactions.Code:<!-- Local DataSource that works in any environment --> <bean id="myDataSource" name="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName"><value>${jdbc.driverClassName}</value></property> <property name="url"><value>${jdbc.url}</value></property> <property name="username"><value>${jdbc.username}</value></property> <property name="password"><value>${jdbc.password}</value></property> </bean> <bean id="mySessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="myDataSource"/> </property> <property name="mappingResources"> <list> <value> program.hbm.xml</value> <value> budgetallocation.hbm.xml</value> <value> bonusallocation.hbm.xml</value> <value> programguideline.hbm.xml</value> <value> notification.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.query.substitutions">true=1 false=0</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager"> <property name="sessionFactory"> <ref local="mySessionFactory"/> </property> </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate.HibernateTemplate" > <property name="sessionFactory"> <ref local="mySessionFactory"/> </property> </bean>
My BaseTestClass does the following:Code:<bean id="programInfo" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager"> <ref bean="transactionManager"/> </property> <property name="target"> <bean id="programInfoTarget" class="ProgramInfoDAO"> <property name="sessionFactory"> <ref bean="mySessionFactory"/> </property> </bean> </property> <property name="transactionAttributes"> <props> <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="load*">PROPAGATION_NESTED,readOnly</prop> <prop key="store*">PROPAGATION_REQUIRED</prop> </props> </property> </bean>
Since HibernateTransactionManager is managing everything, I thought everything work ok. Can someone help?Code:this.transactionStatus = transactionManager.getTransaction(new DefaultTransactionDefinition()); ((AbstractPlatformTransactionManager)transactionManager).setNestedTransactionAllowed(true); hibernateTemplate = (HibernateTemplate)applicationContext.getBean("hibernateTemplate" ); logger.info("Began transaction: transaction manager=[" + this.transactionManager + "]; defaultCommit=" + this.complete);
Take Care
Jason


Reply With Quote
.