Hello,
I'm trying to configure the subject line to use two different connections to an Oracle DB and use JTA to manage the transactions across both. I have been pouring over the documentation and have yet to find an example of such a setup.
The current issue is I'm getting the following exception when I try to retrieve info from a DB table.
Code:
[6/25/04 9:36:22:702 CDT] 37e0c3d3 JDBCException E net.sf.hibernate.util.JDBCExceptionReporter TRAS0014I: The following exception was logged com.ibm.ejs.cm.exception.WorkRolledbackException: Outstanding work on this connection which was not comitted or rolledback by the user has been rolledback.
I read through the Spring JtaTransaction java doc many times as well as the hibernate docs and have hit a brick wall. Here is my spring configuration
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<!--
[ snipped out the comments to save space ]
-->
<beans>
<bean id="CodeDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>jdbc/codeds</value>
</property>
</bean>
<bean id="ControlDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>jdbc/controlds</value>
</property>
</bean>
<bean id="ControlSessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
<property name="dataSource"><ref local="ControlDataSource"/></property>
<property name="mappingResources">
<list>
<value>springtest/Control.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.statement_cache.size">0</prop>
<prop key="hibernate.transaction.manager_lookup_class">net.sf.hibernate.transaction.WebSphereTransactionManagerLookup</prop>
</props>
</property>
</bean>
<bean id="CodeSessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
<property name="dataSource"><ref local="CodeDataSource"/></property>
<property name="mappingResources">
<list>
<value>springtest/Code.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.statement_cache.size">0</prop>
<prop key="hibernate.transaction.manager_lookup_class">net.sf.hibernate.transaction.WebSphereTransactionManagerLookup</prop>
</props>
</property>
</bean>
<!-- WebSphere Transaction Manager Factory for spring to use to find the JTA transaction
in WebSphere -->
<bean id="WSTransactionFactory" class="org.springframework.transaction.jta.WebSphereTransactionManagerFactoryBean"/>
<bean id="JTATransactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager"><ref local="WSTransactionFactory"/></property>
</bean>
<bean id="CodeDataAccessObject" class="springtest.CodeDAO">
<property name="sessionFactory"><ref local="CodeSessionFactory"/></property>
</bean>
<bean id="ControlDataAccessObject" class="springtest.ControlDAO">
<property name="sessionFactory"><ref local="ControlSessionFactory"/></property>
</bean>
<bean id="ControlBusinessObjectTarget" class="springtest.ControlBusinessObjectImpl">
<property name="codeDataAccessObject"><ref local="CodeDataAccessObject"/></property>
<property name="controlDataAccessObject"><ref local="ControlDataAccessObject"/></property>
</bean>
<bean id="ControlBusinessObject" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="JTATransactionManager"/>
</property>
<property name="target">
<ref bean="ControlBusinessObjectTarget"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="getControl*">PROPAGATION_SUPPORTS</prop>
</props>
</property>
</bean>
</beans>
Here is the code for my ControlDAO
Code:
package springtest;
import net.sf.hibernate.*;
import java.util.*;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate.HibernateTemplate;
import org.springframework.orm.hibernate.SessionFactoryUtils;
public class ControlDAO extends AbstractDAO {
public Control addControl(Control person) throws DataAccessException {
Session session = SessionFactoryUtils.getSession(getSessionFactory(),
true);
try {
session.save(person);
session.flush();
} catch (HibernateException e) {
throw SessionFactoryUtils.convertHibernateAccessException(e);
} finally {
SessionFactoryUtils.closeSessionIfNecessary(session,getSessionFactory());
}
return person;
}
public List findAllControls() throws DataAccessException {
List controls = null;
controls = getHibernateTemplate().find("from Control as control");
System.out.println("Returning list");
return controls;
}
}
When I start the server, I get the following output
Code:
[6/25/04 9:34:45:257 CDT] 5fdf03c3 ManagerAdmin I TRAS0017I: The startup trace state is *=all=disabled.
[6/25/04 9:34:46:196 CDT] 5fdf03c3 AdminInitiali A ADMN0015I: AdminService initialized
[6/25/04 9:34:47:778 CDT] 5fdf03c3 Configuration A SECJ0215I: Successfully set JAAS login provider configuration class to com.ibm.ws.security.auth.login.Configuration.
[6/25/04 9:34:47:841 CDT] 5fdf03c3 SecurityDM I SECJ0231I: The Security component's FFDC Diagnostic Module com.ibm.ws.security.core.SecurityDM registered successfully: true.
[6/25/04 9:34:48:499 CDT] 5fdf03c3 SecurityCompo I SECJ0309I: Java 2 Security is disabled.
[6/25/04 9:34:48:562 CDT] 5fdf03c3 SecurityCompo I SECJ0212I: WCCM JAAS configuration information successfully pushed to login provider class.
[6/25/04 9:34:48:656 CDT] 5fdf03c3 SecurityCompo I SECJ0240I: Security service initialization completed successfully
[6/25/04 9:34:48:671 CDT] 5fdf03c3 JMSRegistrati A MSGS0602I: WebSphere Embedded Messaging Client only has been installed
[6/25/04 9:34:52:008 CDT] 5fdf03c3 JMXSoapAdapte A ADMC0013I: SOAP connector available at port 8880
[6/25/04 9:34:52:023 CDT] 5fdf03c3 SecurityCompo I SECJ0243I: Security service started successfully
[6/25/04 9:34:52:023 CDT] 5fdf03c3 SecurityCompo I SECJ0210I: Security enabled false
[6/25/04 9:34:53:136 CDT] 5fdf03c3 ResourceMgrIm I WSVR0049I: Binding CodeDS as jdbc/codeds
[6/25/04 9:34:53:198 CDT] 5fdf03c3 ResourceMgrIm I WSVR0049I: Binding ControlDS as jdbc/controlds
[6/25/04 9:34:54:498 CDT] 5fdf03c3 CacheServiceI I DYNA0048I: WebSphere Dynamic Cache initialized successfully.
[6/25/04 9:34:54:890 CDT] 5fdf03c3 FileBeanStore W CNTR0023W: Directory "C:\Program Files\IBM\WebSphere Studio\runtimes\base_v5/temp" does not exist. The EJB Container will use the current directory for passivating beans.
[6/25/04 9:34:57:584 CDT] 5fdf03c3 ApplicationMg A WSVR0200I: Starting application: IBMUTC
[6/25/04 9:34:58:179 CDT] 5fdf03c3 WebContainer A SRVE0161I: IBM WebSphere Application Server - Web Container. Copyright IBM Corp. 1998-2002
[6/25/04 9:34:58:211 CDT] 5fdf03c3 WebContainer A SRVE0162I: Servlet Specification Level: 2.3
[6/25/04 9:34:58:211 CDT] 5fdf03c3 WebContainer A SRVE0163I: Supported JSP Specification Level: 1.2
[6/25/04 9:34:58:336 CDT] 5fdf03c3 WebContainer A SRVE0169I: Loading Web Module: IBM Universal Test Client.
[6/25/04 9:34:58:618 CDT] 5fdf03c3 WebGroup I SRVE0180I: [IBM Universal Test Client] [/UTC] [Servlet.LOG]: JSP 1.2 Processor: init
[6/25/04 9:34:58:822 CDT] 5fdf03c3 WebGroup I SRVE0180I: [IBM Universal Test Client] [/UTC] [Servlet.LOG]: SimpleFileServlet: init
[6/25/04 9:34:59:104 CDT] 5fdf03c3 ApplicationMg A WSVR0221I: Application started: IBMUTC
[6/25/04 9:34:59:104 CDT] 5fdf03c3 ApplicationMg A WSVR0200I: Starting application: SpringTestEar
[6/25/04 9:34:59:386 CDT] 5fdf03c3 WebContainer A SRVE0169I: Loading Web Module: SpringTest.war.
[6/25/04 9:34:59:417 CDT] 5fdf03c3 WebGroup I SRVE0180I: [SpringTest.war] [/SpringTest] [Servlet.LOG]: JSP 1.2 Processor: init
[6/25/04 9:35:01:359 CDT] 5fdf03c3 WebGroup I SRVE0180I: [SpringTest.war] [/SpringTest] [Servlet.LOG]: SimpleFileServlet: init
[6/25/04 9:35:01:375 CDT] 5fdf03c3 WebGroup I SRVE0180I: [SpringTest.war] [/SpringTest] [Servlet.LOG]: InvokerServlet: init
[6/25/04 9:35:01:641 CDT] 5fdf03c3 WebGroup I SRVE0180I: [SpringTest.war] [/SpringTest] [Servlet.LOG]: SpringContextLoader: init
[6/25/04 9:35:01:892 CDT] 5fdf03c3 WebGroup I SRVE0180I: [SpringTest.war] [/SpringTest] [Servlet.LOG]: Loading root WebApplicationContext
[6/25/04 9:35:02:111 CDT] 5fdf03c3 XmlBeanDefini I org.springframework.beans.factory.xml.XmlBeanDefinitionReader Loading XML bean definitions from resource [/WEB-INF/applicationContext.xml] of ServletContext
[6/25/04 9:35:02:503 CDT] 5fdf03c3 XmlWebApplica I org.springframework.web.context.support.XmlWebApplicationContext Bean factory for application context [Root XmlWebApplicationContext]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [CodeDataSource,ControlDataSource,ControlSessionFactory,CodeSessionFactory,WSTransactionFactory,JTATransactionManager,CodeDataAccessObject,ControlDataAccessObject,ControlBusinessObjectTarget,ControlBusinessObject]; Root of BeanFactory hierarchy
[6/25/04 9:35:02:518 CDT] 5fdf03c3 XmlWebApplica I org.springframework.web.context.support.XmlWebApplicationContext 10 beans defined in ApplicationContext [Root XmlWebApplicationContext]
[6/25/04 9:35:02:550 CDT] 5fdf03c3 XmlWebApplica I org.springframework.web.context.support.XmlWebApplicationContext No MessageSource found for context [Root XmlWebApplicationContext]: using empty StaticMessageSource
[6/25/04 9:35:02:581 CDT] 5fdf03c3 UiApplication I org.springframework.ui.context.support.UiApplicationContextUtils No ThemeSource found for [Root XmlWebApplicationContext]: using ResourceBundleThemeSource
[6/25/04 9:35:02:597 CDT] 5fdf03c3 XmlWebApplica I org.springframework.web.context.support.XmlWebApplicationContext Refreshing listeners
[6/25/04 9:35:02:597 CDT] 5fdf03c3 DefaultListab I org.springframework.beans.factory.support.DefaultListableBeanFactory Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [CodeDataSource,ControlDataSource,ControlSessionFactory,CodeSessionFactory,WSTransactionFactory,JTATransactionManager,CodeDataAccessObject,ControlDataAccessObject,ControlBusinessObjectTarget,ControlBusinessObject]; Root of BeanFactory hierarchy]
[6/25/04 9:35:02:597 CDT] 5fdf03c3 DefaultListab I org.springframework.beans.factory.support.DefaultListableBeanFactory Creating shared instance of singleton bean 'CodeDataSource'
[6/25/04 9:35:02:894 CDT] 5fdf03c3 DefaultListab I org.springframework.beans.factory.support.DefaultListableBeanFactory Creating shared instance of singleton bean 'ControlDataSource'
[6/25/04 9:35:02:926 CDT] 5fdf03c3 DefaultListab I org.springframework.beans.factory.support.DefaultListableBeanFactory Creating shared instance of singleton bean 'ControlSessionFactory'
[6/25/04 9:35:03:161 CDT] 5fdf03c3 Environment I net.sf.hibernate.cfg.Environment Hibernate 2.1.4
[6/25/04 9:35:03:161 CDT] 5fdf03c3 Environment I net.sf.hibernate.cfg.Environment hibernate.properties not found
[6/25/04 9:35:03:161 CDT] 5fdf03c3 Environment I net.sf.hibernate.cfg.Environment using CGLIB reflection optimizer
[6/25/04 9:35:03:176 CDT] 5fdf03c3 Environment I net.sf.hibernate.cfg.Environment JVM does not support Statement.getGeneratedKeys()
[6/25/04 9:35:03:192 CDT] 5fdf03c3 Environment I net.sf.hibernate.cfg.Environment JVM does not support LinkedHasMap, LinkedHashSet - ordered maps and sets disabled
[6/25/04 9:35:03:192 CDT] 5fdf03c3 Environment I net.sf.hibernate.cfg.Environment using workaround for JVM bug in java.sql.Timestamp
[6/25/04 9:35:03:740 CDT] 5fdf03c3 Binder I net.sf.hibernate.cfg.Binder Mapping class: springtest.Control -> AUTOVIH.CONTROLTABLE
[6/25/04 9:35:04:053 CDT] 5fdf03c3 LocalSessionF I org.springframework.orm.hibernate.LocalSessionFactoryBean Building new Hibernate SessionFactory
[6/25/04 9:35:04:053 CDT] 5fdf03c3 Configuration I net.sf.hibernate.cfg.Configuration processing one-to-many association mappings
[6/25/04 9:35:04:053 CDT] 5fdf03c3 Configuration I net.sf.hibernate.cfg.Configuration processing one-to-one association property references
[6/25/04 9:35:04:053 CDT] 5fdf03c3 Configuration I net.sf.hibernate.cfg.Configuration processing foreign key constraints
[6/25/04 9:35:04:147 CDT] 5fdf03c3 Dialect I net.sf.hibernate.dialect.Dialect Using dialect: net.sf.hibernate.dialect.OracleDialect
[6/25/04 9:35:04:147 CDT] 5fdf03c3 SettingsFacto I net.sf.hibernate.cfg.SettingsFactory Use outer join fetching: true
[6/25/04 9:35:04:179 CDT] 5fdf03c3 ConnectionPro I net.sf.hibernate.connection.ConnectionProviderFactory Initializing connection provider: org.springframework.orm.hibernate.LocalDataSourceConnectionProvider
[6/25/04 9:35:04:194 CDT] 5fdf03c3 TransactionMa I net.sf.hibernate.transaction.TransactionManagerLookupFactory instantiating TransactionManagerLookup: net.sf.hibernate.transaction.WebSphereTransactionManagerLookup
[6/25/04 9:35:04:210 CDT] 5fdf03c3 TransactionMa I net.sf.hibernate.transaction.TransactionManagerLookupFactory instantiated TransactionManagerLookup
[6/25/04 9:35:05:541 CDT] 5fdf03c3 SettingsFacto I net.sf.hibernate.cfg.SettingsFactory Use scrollable result sets: true
[6/25/04 9:35:05:541 CDT] 5fdf03c3 SettingsFacto I net.sf.hibernate.cfg.SettingsFactory Use JDBC3 getGeneratedKeys(): false
[6/25/04 9:35:05:541 CDT] 5fdf03c3 SettingsFacto I net.sf.hibernate.cfg.SettingsFactory Optimize cache for minimal puts: false
[6/25/04 9:35:05:541 CDT] 5fdf03c3 SettingsFacto I net.sf.hibernate.cfg.SettingsFactory echoing all SQL to stdout
[6/25/04 9:35:05:541 CDT] 5fdf03c3 SettingsFacto I net.sf.hibernate.cfg.SettingsFactory Query language substitutions: {}
[6/25/04 9:35:05:541 CDT] 5fdf03c3 SettingsFacto I net.sf.hibernate.cfg.SettingsFactory cache provider: net.sf.ehcache.hibernate.Provider
[6/25/04 9:35:05:682 CDT] 5fdf03c3 Configuration I net.sf.hibernate.cfg.Configuration instantiating and configuring caches
[6/25/04 9:35:06:074 CDT] 5fdf03c3 SessionFactor I net.sf.hibernate.impl.SessionFactoryImpl building session factory
[6/25/04 9:35:07:672 CDT] 5fdf03c3 SessionFactor I net.sf.hibernate.impl.SessionFactoryObjectFactory no JNDI name configured
[6/25/04 9:35:07:672 CDT] 5fdf03c3 WebSphereTran I net.sf.hibernate.transaction.WebSphereTransactionManagerLookup WebSphere 5.0
[6/25/04 9:35:07:672 CDT] 5fdf03c3 DefaultListab I org.springframework.beans.factory.support.DefaultListableBeanFactory Creating shared instance of singleton bean 'CodeSessionFactory'
[6/25/04 9:35:07:797 CDT] 5fdf03c3 Binder I net.sf.hibernate.cfg.Binder Mapping class: springtest.Code -> AUTOVIH.CODETABLE
[6/25/04 9:35:07:797 CDT] 5fdf03c3 LocalSessionF I org.springframework.orm.hibernate.LocalSessionFactoryBean Building new Hibernate SessionFactory
[6/25/04 9:35:07:797 CDT] 5fdf03c3 Configuration I net.sf.hibernate.cfg.Configuration processing one-to-many association mappings
[6/25/04 9:35:07:797 CDT] 5fdf03c3 Configuration I net.sf.hibernate.cfg.Configuration processing one-to-one association property references
[6/25/04 9:35:07:797 CDT] 5fdf03c3 Configuration I net.sf.hibernate.cfg.Configuration processing foreign key constraints
[6/25/04 9:35:07:797 CDT] 5fdf03c3 Dialect I net.sf.hibernate.dialect.Dialect Using dialect: net.sf.hibernate.dialect.OracleDialect
[6/25/04 9:35:07:797 CDT] 5fdf03c3 SettingsFacto I net.sf.hibernate.cfg.SettingsFactory Use outer join fetching: true
[6/25/04 9:35:07:797 CDT] 5fdf03c3 ConnectionPro I net.sf.hibernate.connection.ConnectionProviderFactory Initializing connection provider: org.springframework.orm.hibernate.LocalDataSourceConnectionProvider
[6/25/04 9:35:07:797 CDT] 5fdf03c3 TransactionMa I net.sf.hibernate.transaction.TransactionManagerLookupFactory instantiating TransactionManagerLookup: net.sf.hibernate.transaction.WebSphereTransactionManagerLookup
[6/25/04 9:35:07:797 CDT] 5fdf03c3 TransactionMa I net.sf.hibernate.transaction.TransactionManagerLookupFactory instantiated TransactionManagerLookup
[6/25/04 9:35:07:969 CDT] 5fdf03c3 SettingsFacto I net.sf.hibernate.cfg.SettingsFactory Use scrollable result sets: true
[6/25/04 9:35:07:969 CDT] 5fdf03c3 SettingsFacto I net.sf.hibernate.cfg.SettingsFactory Use JDBC3 getGeneratedKeys(): false
[6/25/04 9:35:07:969 CDT] 5fdf03c3 SettingsFacto I net.sf.hibernate.cfg.SettingsFactory Optimize cache for minimal puts: false
[6/25/04 9:35:07:969 CDT] 5fdf03c3 SettingsFacto I net.sf.hibernate.cfg.SettingsFactory echoing all SQL to stdout
[6/25/04 9:35:07:969 CDT] 5fdf03c3 SettingsFacto I net.sf.hibernate.cfg.SettingsFactory Query language substitutions: {}
[6/25/04 9:35:08:032 CDT] 5fdf03c3 SettingsFacto I net.sf.hibernate.cfg.SettingsFactory cache provider: net.sf.ehcache.hibernate.Provider
[6/25/04 9:35:08:032 CDT] 5fdf03c3 Configuration I net.sf.hibernate.cfg.Configuration instantiating and configuring caches
[6/25/04 9:35:08:032 CDT] 5fdf03c3 SessionFactor I net.sf.hibernate.impl.SessionFactoryImpl building session factory
[6/25/04 9:35:08:095 CDT] 5fdf03c3 SessionFactor I net.sf.hibernate.impl.SessionFactoryObjectFactory no JNDI name configured
[6/25/04 9:35:08:095 CDT] 5fdf03c3 WebSphereTran I net.sf.hibernate.transaction.WebSphereTransactionManagerLookup WebSphere 5.0
[6/25/04 9:35:08:095 CDT] 5fdf03c3 DefaultListab I org.springframework.beans.factory.support.DefaultListableBeanFactory Creating shared instance of singleton bean 'WSTransactionFactory'
[6/25/04 9:35:08:095 CDT] 5fdf03c3 WebSphereTran I org.springframework.transaction.jta.WebSphereTransactionManagerFactoryBean Found WebSphere 5.0: com.ibm.ejs.jts.jta.TransactionManagerFactory
[6/25/04 9:35:08:110 CDT] 5fdf03c3 DefaultListab I org.springframework.beans.factory.support.DefaultListableBeanFactory Creating shared instance of singleton bean 'JTATransactionManager'
[6/25/04 9:35:08:157 CDT] 5fdf03c3 JtaTransactio I org.springframework.transaction.jta.JtaTransactionManager Using JTA UserTransaction [com.ibm.ejs.jts.jta.UserTransactionImpl@4a6903c8] from JNDI location [java:comp/UserTransaction]
[6/25/04 9:35:08:157 CDT] 5fdf03c3 DefaultListab I org.springframework.beans.factory.support.DefaultListableBeanFactory Creating shared instance of singleton bean 'CodeDataAccessObject'
[6/25/04 9:35:08:298 CDT] 5fdf03c3 DefaultListab I org.springframework.beans.factory.support.DefaultListableBeanFactory Creating shared instance of singleton bean 'ControlDataAccessObject'
[6/25/04 9:35:08:361 CDT] 5fdf03c3 DefaultListab I org.springframework.beans.factory.support.DefaultListableBeanFactory Creating shared instance of singleton bean 'ControlBusinessObjectTarget'
[6/25/04 9:35:08:392 CDT] 5fdf03c3 DefaultListab I org.springframework.beans.factory.support.DefaultListableBeanFactory Creating shared instance of singleton bean 'ControlBusinessObject'
[6/25/04 9:35:08:862 CDT] 5fdf03c3 ContextLoader I org.springframework.web.context.ContextLoader Using context class [org.springframework.web.context.support.XmlWebApplicationContext] for root WebApplicationContext
[6/25/04 9:35:08:878 CDT] 5fdf03c3 ContextLoader I org.springframework.web.context.ContextLoader Published root WebApplicationContext [org.springframework.web.context.support.XmlWebApplicationContext: displayName=[Root XmlWebApplicationContext]; startup date=[Fri Jun 25 09:35:01 CDT 2004]; root of ApplicationContext hierarchy; config locations=[/WEB-INF/applicationContext.xml]; ] as ServletContext attribute with name [interface org.springframework.web.context.WebApplicationContext.ROOT]
.... [ snipped out all the struts stuff ] ....
[6/25/04 9:35:13:624 CDT] 5fdf03c3 WsServer A WSVR0001I: Server server1 open for e-business
I'm stuck. I've tried all kinds of different things in the configuration file. I've also tried different ways of getting the session (getHibernateTemplate and SessionFactoryUtils). What am I missing?