I have configured a sample application with Jencks for using a JTA
TransactionManager, Outbound JMS, and Outbound JDBC. I am using Jencks 2.0,
Tranql 1.4-SNAPSHOT, Tranql Connector 1.3-SNAPSHOT, ActiveMQ-4.1.0,
ActiveMQ-RA-4.1.0-incubator, Spring 2.0.2, and Hibernate 3.2.1.ga. I'm
currently using an Oracle 10g database for testing.
I have written three test cases, all of which involve a test method which
performs one JDBC update and one JMS message send, and the method is wired
via Spring AOP to participate in a transaction managed by the JTA
TransactionManager configured through Jencks.
The first test case has no errors and the data should be persisted in the
database and the message should go to the JMS Queue.
The second test case has a hard-coded JDBC error and so both the JDBC update
and the JMS message send should be rolled back, with no data added to the
database and no message in the Queue.
The third test case has a hard coded JMS error and so again both the JDBC
update and the JMS message send should be rolled back, with no data added to
the database and no message in the Queue.
The second and third test cases work as expected, in that the message never
shows up in the ActiveMQ Queue, and the data never appears in the database.
However the first test case is failing because although there are no
exceptions and the message makes it to the Queue with no problem the data
never shows up in the database as it should.
I have created a test of my example DAO using the same Tranql DataSource,
JTA TransactionManager, and ConnectionManager, and I can run the test
without error but I never see the data inserted into the database table. So
I'm assuming that there is something amiss with the Tranql
DataSource/ManagedConnectionFactory configuration.
If I use a normal DataSource (i.e. org.apache.commons.dbcp.BasicDataSource
without the JDBC ConnectionManager) then the data gets inserted into the
database without a problem, but in the third test case above the data insert
is not rolled back since the JDBC isn't participating in the XA transaction.
Below is my persistence configuration, maybe someone can see what I'm doing
wrong?
<beans>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- JDBC Managed Connection Factory -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<bean id="jdbcManagedConnectionFactory"
class="org.jencks.tranql.DataSourceMCF">
<property name="driverName" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- JTA Transaction Manager -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~ -->
<bean id="transactionManager"
class="org.jencks.factory.TransactionManagerFactoryBean"/>
<!-- ~~~~~~~~~~~~~~~~~~ -->
<!-- Connection Manager -->
<!-- ~~~~~~~~~~~~~~~~~~ -->
<bean id="jdbcConnectionManager"
class="org.jencks.factory.ConnectionManagerFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
</bean>
<!-- ~~~~~~~~~~~~~~~ -->
<!-- JDBC DataSource -->
<!-- ~~~~~~~~~~~~~~~ -->
<bean id="dataSource"
class="org.jencks.factory.ConnectionFactoryFactoryBean">
<property name="managedConnectionFactory"
ref="jdbcManagedConnectionFactory"/>
<property name="connectionManager" ref="jdbcConnectionManager"/>
</bean>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- Factory bean for Hibernate Sessions -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<bean id="hibernateSessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="annotatedClasses">
<list>
<value>com.mycom.jta.model.Example</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop
key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
<prop
key="hibernate.cache.use_second_level_cache">false</prop>
<prop key="jdbc.batch_size">20</prop>
<prop key="hibernate.query.substitutions">true 1, false
0</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- transactional AOP advice which can be used by AOP pointcuts -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<tx:advice id="persistenceTxAdvice"
transaction-manager="transactionManager">
<tx:attributes>
<!-- all methods starting with 'get' are read-only -->
<tx:method name="get*" read-only="true" />
<!-- other methods use the default transaction settings (see
below) -->
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- AOP configuration specifying a pointcut and advisor -->
<!-- for applying the transactional advice declared above -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<aop:config>
<aop:pointcut id="persistenceOperations"
expression="execution(*
com.mycom.jta.persistence.*.*(..))" />
<aop:advisor advice-ref="persistenceTxAdvice"
pointcut-ref="persistenceOperations" />
</aop:config>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- DAO for Example objects -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<bean id="exampleDao"
class="com.mycom.jta.persistence.ExampleDaoHibernateImpl">
<property name="sessionFactory" ref="hibernateSessionFactory" />
<property name="persistentClass" value="com.mycom.jta.model.Example"
/>
</bean>
</beans>
Thanks in advance for any suggestions as to where I might search for the
problem, what I'm obviously doing wrong, etc.
--James
--
View this message in context:
http://www.nabble.com/Data-never-inserted-updated-using-Outbound-JDBC-with-a-Tranql-DataSourceMCF-tf3127154.html#a8664339
Sent from the jencks - user mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email