I'm having two databases running in parallel.
I created two configs with different GenericDAOs/SessionFactories for each one, however the second SessionFactory to be instantiated have issues. When I try to getCurrentSession() I get this error : org.hibernate.HibernateException: No Session found for current thread.
Config1.xml :
<bean id="mainDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/main" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<bean id="mainSessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="mainDataSource" />
<property name="annotatedClasses">
<list>
<value>com.avocat.domain.entities.main.User</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<bean id="mainTransactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="dataSource" ref="mainDataSource" />
<property name="sessionFactory" ref="mainSessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="mainTransactionManager" />
<context:annotation-config />
Config2.xml :
<bean id="fakeDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/fake" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<bean id="fakeSessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="fakeDataSource" />
<property name="annotatedClasses">
<list>
<value>com.avocat.domain.entities.intra.Bla</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<bean id="fakeTransactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="dataSource" ref="fakeDataSource" />
<property name="sessionFactory" ref="fakeSessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="fakeTransactionManager" />
<context:annotation-config />
MainGenericDAO :
#Autowired
#Qualifier("mainSessionFactory")
private SessionFactory mainSessionFactory;
protected Session currentSession()
{
return mainSessionFactory.getCurrentSession();
}
FakeGenericDAO :
#Autowired
#Qualifier("fakeSessionFactory")
private SessionFactory fakeSessionFactory;
protected Session currentSession()
{
return fakeSessionFactory.getCurrentSession();
}
Config1 is declared before Config2.
Also, queries using MainGenericDAO/MainSessionFactory are OK.
But currentSession() from FakeGenericDAO returns the error.
It seems that the transaction is not created on your second DAO for the FakeSessionFactory. You must use #Transactional("fakeTransactionManager") on the FakeGenericDAO.
Related
I'm trying to persist an entity using EntityManagerFactory defined in my bean. The function looks like this:
private BaseMasterEntity saveEntity(BaseMasterEntity entity){
EntityManagerFactory emf = (EntityManagerFactory)context.getBean("entityManagerFactory");
EntityManager sf = emf.createEntityManager();
sf.getTransaction().begin();
sf.persist(entity);
sf.getTransaction().commit();
sf.close();
return entity;
}
The problem here is when it persists it cannot find the entity. The entity has #Entity defined clearly with the javax.persistance annotation. This is how my context file looks btw:
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="*my jdbc setting*" />
<property name="username" value="hr" />
<property name="password" value="hr" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter" />
<property name="packagesToScan"
value="classpath*:com.samplewebentities"></property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="hibernateJpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
<tx:annotation-driven transaction-manager="transactionManager" />
If it helps, the classpath*:com.samplewebentites is a different component (The application is a combination of many different components/projects: Using SCA here).
No need for classpath
..
<property name="packagesToScan"
value="com.samplewebentities"></property>
..
i am a newbie to spring and hibernate..Here in my scenario, i am building an application where it can connect to different environments Db's(devl,qual,prod) based on the environment selected by the user..For this I am making multiple SessionFactory beans and distinguishing them using #Qualifier in DAO classes based on the env selected by the user..
Here i am struck at, how to configure multi-TransactionManagers if they are required or not in my case and how to deal with the code if the multi-TransactionManagers are not required..?
So I was not sure of how to use different TransactionManagers per env, for the same save method which will save the user form data in the DB..Below is my spring .xml file and the DAO class code which is used to distinguish the sessionFactory w.r.t env..
Help needed in configuring multiple TransactionManagers or can I discard the use of TransactionManager and simply distinguish the transaction with Hibernate session(beginTransaction)..!!
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSourceProd" />
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="dataSourceProd" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="url" value="jdbc:sqlserver://localhost:1433;databaseName=SM_PROD" />
<property name="username" value="sa" />
<property name="password" value="123" />
</bean>
<!-- Hibernate Properties -->
<bean id="prodSessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSourceProd" />
<property name="packagesToScan" value="com.deere.dsfj.siteMinder.domain" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<bean id="dataSourceDevl" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="url" value="jdbc:sqlserver://localhost:1433;databaseName=SM_Devl" />
<property name="username" value="sa" />
<property name="password" value="123" />
</bean>
<bean id="DevlSessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSourceDevl" />
<property name="packagesToScan" value="com.deere.dsfj.siteMinder.domain" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
Below is the DAO code..
public void BeginTransaction(String targetEnv)
{
getCurrentSession(targetEnv).getTransaction().begin();
}
#Autowired
#Qualifier("DevlSessionFactory")
private SessionFactory devlSessionFactory;
#Autowired
#Qualifier("prodSessionFactory")
private SessionFactory prodSessionFactory;
protected final Session getCurrentSession(String targetEnv)
{
if(targetEnv!=null && !"".equals(targetEnv) && targetEnv.equals("Devl"))
{
return devlSessionFactory.getCurrentSession();
}
else if(targetEnv!=null && !"".equals(targetEnv) && targetEnv.equals("PROD"))
{
return prodSessionFactory.getCurrentSession();
}
return null;
}
Appreciate the help...
Hi this is what I am looking to do -
I have three databases - each exactly the same - one is primary and two and three are back ups.
I am using hibernate and spring to connect to the data base.I have spring application context file configured with 3 session factories, and 3 corresponding data sources.
I was wondering if there is a way using spring where if the application is not able to connect to the database 1 (an exception is thrown) it will connect to database 2 - and in turn is database 3 is down it will connect to 3 and proceed.
What would be the best way to implement this? I have read about AbstractRoutingDataSource ..but not sure how to make use of that in this case..also if there are other ideas.. Would appreciate some directions. Thanks!
this is my config in application context xml -
<bean id="dataSource1" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="$g{jdbc.driverClassName}" />
<property name="jdbcUrl" value="$g{url1}" />
<property name="user" value="$l{uid1}" />
<property name="password" value="$l{pwd1}" />
<property name="minPoolSize" value="$g{jdbc.minPoolSize}" />
<property name="maxPoolSize" value="$g{jdbc.maxPoolSize}" />
<property name="preferredTestQuery" value="$g{jdbc.preferredTestQuery}" />
<property name="testConnectionOnCheckout" value="$g{jdbc.testConnectionOnCheckout}" />
</bean>
<bean id="sessionFactory1"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource1" />
<property name="packagesToScan">
<list>
<value>com.model</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
<prop key="hibernate.dialect">$g{jdbc.dialect}</prop>
<prop key="hibernate.show_sql">$g{jdbc.show_sql}</prop>
</props>
</property>
</bean>
<bean id="dataSource2" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="$g{jdbc.driverClassName}" />
<property name="jdbcUrl" value="$g{url2}" />
<property name="user" value="$l{uid2}" />
<property name="password" value="$l{pwd2}" />
<property name="minPoolSize" value="$g{jdbc.minPoolSize}" />
<property name="maxPoolSize" value="$g{jdbc.maxPoolSize}" />
<property name="preferredTestQuery" value="$g{jdbc.preferredTestQuery}" />
<property name="testConnectionOnCheckout" value="$g{jdbc.testConnectionOnCheckout}" />
</bean>
<bean id="sessionFactory2"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource2" />
<property name="packagesToScan">
<list>
<value>com.model</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
<prop key="hibernate.dialect">$g{jdbc.dialect}</prop>
<prop key="hibernate.show_sql">$g{jdbc.show_sql}</prop>
</props>
</property>
</bean>
<bean id="dataSource3" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="$g{jdbc.driverClassName}" />
<property name="jdbcUrl" value="$g{url3}" />
<property name="user" value="$l{uid3}" />
<property name="password" value="$l{pwd3}" />
<property name="minPoolSize" value="$g{jdbc.minPoolSize}" />
<property name="maxPoolSize" value="$g{jdbc.maxPoolSize}" />
<property name="preferredTestQuery" value="$g{jdbc.preferredTestQuery}" />
<property name="testConnectionOnCheckout" value="$g{jdbc.testConnectionOnCheckout}" />
</bean>
<bean id="sessionFactory3"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource3" />
<property name="packagesToScan">
<list>
<value>com.model</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
<prop key="hibernate.dialect">$g{jdbc.dialect}</prop>
<prop key="hibernate.show_sql">$g{jdbc.show_sql}</prop>
</props>
</property>
</bean>
<bean id="transactionManager1"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory1" />
</bean>
<bean id="transactionManager2"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory2" />
</bean>
<bean id="transactionManager3"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory3" />
</bean>
There is a way to achieve this by using Spring Abstract Data Source Routing mechanism -
https://spring.io/blog/2007/01/23/dynamic-datasource-routing/
I'm working on a web application that uses Spring MVC 3 and Hibernate
I want to use 2 datasource MySql and Oracle databases for my web application,
I've been read many tutorial and problem solving for "spring-hibernate multiple datasource/database"
for example :
directjump2java.blogspot.com
stackoverflow
forum spring
and etc.
but when every single time I run it, the config just read my first database config (MySql)
and show this error Table 'db_prod.ksei_lookup_holiday' doesn't exist db.prod is my first database(MySql) and KSEI_LOOKUP_HOLIDAY is my second database (Oracle),
this is my spring.xml
<tx:annotation-driven transaction-manager="transactionManager"/>
<tx:annotation-driven transaction-manager="transactionManagerSOAAPP"/>
<context:annotation-config />
<context:component-scan base-package="prod.support" />
<!-- Database MySql, Desktop -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/db_prod" />
<property name="username" value="root" />
<property name="password" value="shikamaru" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration"></property>
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="packagesToScan" value="prod.support.model.splatter" />
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory">
</bean>
<!-- Database Oracle, Schema : SOAAPP -->
<bean id="dataSourceSOAAPP" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:#localhost:1521:XE" />
<property name="username" value="splatter" />
<property name="password" value="shikamaru" />
</bean>
<bean id="sessionFactorySOAAPP"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration"></property>
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="packagesToScan" value="prod.support.model.soaapp" />
</bean>
<bean id="transactionManagerSOAAPP"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactorySOAAPP">
</bean>
this is my DAO Implementation for my first database (MySql)
#Repository
#Qualifier(value="sessionFactory")
public class UserDaoImpl extends HibernateDaoSupport implements UserDao{
#Autowired
private UserDaoImpl(SessionFactory sessionFactory){
setSessionFactory(sessionFactory);
}
this is my DAO Implementation for my second database (Oracle)
#Repository
#Qualifier(value="sessionFactorySOAAPP")
public class UpdateKSEIDaoImpl extends HibernateDaoSupport implements UpdateKSEIDao{
#Autowired
private UpdateKSEIDaoImpl(SessionFactory sessionFactorySOAAPP){
setSessionFactory(sessionFactorySOAAPP);
}
any help will be pleasure :)
The problem is that you have used
<property name="dataSource" ref="dataSource"></property> in sessionFactorySOAAPP.
You should have used <property name="dataSource" ref="dataSourceSOAAPP"></property>
If you check "sessionFactorySOAAPP" then the below property name should be 'dataSourceSOAAPP' not the 'dataSource'.
this my configuration file:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url"
value="jdbc:mysql://localhost:3306/gl?characterEncoding=UTF-8" />
<property name="username" value="root" />
<property name="password" value="2238295" />
</bean>
<bean id="mainDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url"
value="jdbc:mysql://localhost:3306/gl_main?characterEncoding=UTF-8" />
<property name="username" value="root" />
<property name="password" value="2238295" />
</bean>
<!-- Hibernate 4 SessionFactory Bean definition -->
<bean id="sfAccounting"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.gl.domain.accounting" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.connection.useUnicode">true</prop>
<prop key="hibernate.connection.characterEncoding">UTF-8</prop>
<prop key="hibernate.connection.charSet">UTF-8</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
</bean>
<!-- Hibernate 4 SessionFactory Bean definition -->
<bean id="sfCommon"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="mainDataSource" />
<property name="packagesToScan" value="com.gl.domain.common" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.connection.useUnicode">true</prop>
<prop key="hibernate.connection.characterEncoding">UTF-8</prop>
<prop key="hibernate.connection.charSet">UTF-8</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
</bean>
<tx:annotation-driven transaction-manager="txnManagerAccounting"/>
<tx:annotation-driven transaction-manager="txnManagerCommon"/>
<bean id="txnManagerAccounting"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sfAccounting" />
</bean>
<bean id="txnManagerCommon"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sfCommon" />
</bean>
<bean id="persistenceExceptionTranslationPostProcessor"
class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
#geoand is correct in the error he spotted. Other than that the context xml seems correct and works for me.
However, for me, this only works if #qualifier is with the #Autowired.
#Repository
public class BusinessDaoImpl implements BusinessDao
{
#Autowired
#Qualifier(value="sessionFactory")
SessionFactory sessionFactory;
I have below configuration in my spring config file. I am using Spring3, Hibernate4 and Tomcat7.
<jee:jndi-lookup id="wcDataSource" jndi-name="java:comp/UserTransaction" resource-ref="false" environment-ref="remoteEnv" />
<util:properties id="remoteEnv">
<prop key="java.naming.provider.url">jnp://jndi.myURL.me:1099</prop>
<prop key="java.naming.factory.url.pkgs">org.jboss.naming:org.jnp.interfaces</prop>
<prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
<prop key="jnp.disableDiscovery">true</prop>
</util:properties>
<bean id="dataSourceKS" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${driverClassName}" />
<property name="jdbcUrl" value="${url}" />
<property name="user" value="${username}" />
<property name="password" value="${password}" />
<!-- pool sizing -->
<property name="initialPoolSize" value="15" />
<property name="minPoolSize" value="10" />
<property name="maxPoolSize" value="20" />
<property name="acquireIncrement" value="3" />
<property name="maxStatements" value="6000" />
<property name="maxStatementsPerConnection" value="300" />
</bean>
<bean name="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSourceKS"/>
<property name="annotatedClasses">
<list>
<value>com.sample.MyBean</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.use_sql_comments">true</prop>
<prop key="hibernate.jdbc.batch_size">50</prop>
</props>
</property>
</bean>
Now how can i configure JTATransactionManager here to use #Transactional? Here i have wcDataSource and dataSourceKS. Thanks!
Thanks!
The JtaTransactionManager does not need to know about the DataSource, or any other specific resources, because it uses the container’s global transaction management infrastructure.
So conf file should look like this
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
See http://lafernando.com/2011/01/05/xa-transactions-with-apache-dbcp/ which does it in code but which you should be able to translate to a spring configuration.
Which would result in something like this.
<jee:jndi-lookup id="userTransaction" jndi-name="java:comp/UserTransaction" resource-ref="false" environment-ref="remoteEnv" />
<jee:jndi-lookup id="jtaTransactionManager" jndi-name="java:comp/TransactionManager" resource-ref="false" environment-ref="remoteEnv" />
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<constructor-arg ref="userTransaction"/>
<constructor-arg ref="jtaTransactionManager"/>
</bean>
<util:properties id="remoteEnv">
<prop key="java.naming.provider.url">jnp://jndi.myURL.me:1099</prop>
<prop key="java.naming.factory.url.pkgs">org.jboss.naming:org.jnp.interfaces</prop>
<prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
<prop key="jnp.disableDiscovery">true</prop>
</util:properties>
<bean id="oracleXaDataSource" class="oracle.jdbc.xa.client.OracleXADataSource">
<property name="user" value="${username}" />
<property name="password" value="${password}" />
<property name="url" value="${url}" />
</bean>
<bean id="dataSourceKS" class="org.apache.commons.dbcp.managed.BasicManagedDatasource">
<property name="transactionManager" ref="jtaTransactionManager" />
<property name="xaDataSourceInstance" ref="oracleXaDataSource" />
<property name="initialPoolSize" value="15" />
<property name="minPoolSize" value="10" />
<property name="maxPoolSize" value="20" />
<property name="acquireIncrement" value="3" />
<property name="maxStatements" value="6000" />
<property name="maxStatementsPerConnection" value="300" />
</bean>
<bean name="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="jtaDataSource" ref="dataSourceKS"/>
// .. other hibernate properties
</bean>
Note the change to commons-dbcp as c3p0 doesn't have XA capable implementations.