Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8948925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:07:08+00:00 2026-06-15T13:07:08+00:00

I’m building an application that needs CRUD operations on two separate databases. The transactions

  • 0

I’m building an application that needs CRUD operations on two separate databases. The transactions are applied to one database or the other (never both…so no need for JTA is my understanding). My setup is pretty close to what is found here: Multiple database with Spring+Hibernate+JPA

The problem: My server (JBoss AS7) starts up fine. The application reads from both datasources, say DS1 and DS2, BUT it can only manipulate data from DS1. I can see sequences (Oracle 11g) being updated but no table updates. There are no errors/exceptions thrown. I suspect one of my transaction managers isn’t committing.

Below is a list of technologies used and configuration settings…

Tech Stack

  • JBoss AS7
  • Oracle 11g
  • Spring 3.1
  • JPA 2
  • Hibernate 4.1

persistence-ds1.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
  <persistence-unit name="pu1">
    <class>com.somepackage.EntityA</class>  
    <class>com.somepackage.EntityB</class>  
    <class>com.somepackage.EntityC</class>
    <validation-mode>CALLBACK</validation-mode>
    <properties>
      <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.DefaultNamingStrategy" />
      <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
      <property name="hibernate.hbm2ddl.auto" value="validate" /> 
    </properties>
  </persistence-unit>
</persistence>

persistence-ds2.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
  <persistence-unit name="pu2">
    <class>com.somepackage.EntityD</class>  
    <class>com.somepackage.EntityE</class>  
    <class>com.somepackage.EntityF</class>
    <validation-mode>CALLBACK</validation-mode>
    <properties>
      <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.DefaultNamingStrategy" />
      <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
      <property name="hibernate.hbm2ddl.auto" value="validate" /> 
    </properties>
  </persistence-unit>
</persistence>

applicationContext.xml

<?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:jee="http://www.springframework.org/schema/jee"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
                      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                      http://www.springframework.org/schema/tx
                      http://www.springframework.org/schema/tx/spring-tx.xsd
                      http://www.springframework.org/schema/jee         
                      http://www.springframework.org/schema/jee/spring-jee.xsd">

  <jee:jndi-lookup id="ds1" jndi-name="java:jboss/datasources/DS1"
    expected-type="javax.sql.DataSource" />
  <jee:jndi-lookup id="ds2" jndi-name="java:jboss/datasources/DS2"
    expected-type="javax.sql.DataSource" />     

  <bean id="em1" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
    <property name="entityManagerFactory" ref="emf1" />
    <property name="persistenceUnitName" value="pu1" />
  </bean>
  <bean id="em2" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
    <property name="entityManagerFactory" ref="emf2" />
    <property name="persistenceUnitName" value="pu2" />
  </bean>

  <bean id="emf1" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceXmlLocation" value="classpath*:META-INF/persistence-ds1.xml"/>
    <property name="dataSource" ref="ds1" />
    <property name="jpaVendorAdapter">
      <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="showSql" value="true" />
        <property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect" />
      </bean>
    </property>
    <property name="jpaDialect">
      <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
    </property>
  </bean>
  <bean id="emf2" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceXmlLocation" value="classpath*:META-INF/persistence-ds2.xml"/>
    <property name="dataSource" ref="ds2" />
    <property name="jpaVendorAdapter">
      <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="showSql" value="true" />
        <property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect" />
      </bean>
    </property>
    <property name="jpaDialect">
      <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
    </property>
  </bean>

  <tx:annotation-driven transaction-manager="txm1" />
  <tx:annotation-driven transaction-manager="txm2" />

  <bean id="txm1" class="org.springframework.orm.jpa.JpaTransactionManager">
    <qualifier value="txMgr1"/>
    <property name="entityManagerFactory" ref="emf1" />
    <property name="jpaDialect">
      <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
    </property>
  </bean>
  <bean id="txm2" class="org.springframework.orm.jpa.JpaTransactionManager">
    <qualifier value="txMgr2"/>
    <property name="entityManagerFactory" ref="emf2" />
    <property name="jpaDialect">
      <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
    </property>
  </bean>   

</beans>

In my DAOs, I reference the transaction managers at the class-level as follows.

@Transactional("txm1")
public class DAO1 { ... }

@Transactional("txm2")
public class DAO2 { ... }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:07:10+00:00Added an answer on June 15, 2026 at 1:07 pm

    I resolved my issue!

    In my applicationContext.xml, I removed the following.

    <tx:annotation-driven transaction-manager="txm1" />
    <tx:annotation-driven transaction-manager="txm2" />
    

    And used the following instead.

    <tx:annotation-driven />
    

    But here’s what I believe was the kicker (main problem). In my DAOs, I was assigning the two transaction managers at the class-level. But then I was overriding them with the way I was declaring my methods.

    @Transactional(readOnly = false, value = "txm1")
    public abstract class AbstractJpaDAO1<T extends Serializable> {
    ...
    @Transactional(readOnly = true)
    public T findById(final Long id) {...}
    
    @Transactional
    public boolean insert(final T entity) {...}
    

    As you can see, the @Transaction annotations on the methods were overriding the the one at the class-level. And because there was no transaction manager specified on the methods, Spring defaulted to “transactionManager”, which I didn’t (and still don’t) have declared in my applicaitonContext.xml. So, it was trying to commit using a transaction manager that didn’t exist.

    For the resolution, I just removed the @Transitional annotations on the methods, and kept the one at the class-level.

    @Transactional(readOnly = false, value = "txm1")
    public abstract class AbstractJpaDAO1<T extends Serializable> {
    ...
    public T findById(final Long id) {...}
    
    public boolean insert(final T entity) {...}
    

    Now everything works! I can read/write to two separate databases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.