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

  • Home
  • SEARCH
  • 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 8691823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:12:12+00:00 2026-06-13T00:12:12+00:00

When using @Transactionnal with Spring How does it select the datasource on which it

  • 0

When using @Transactionnal with Spring

  • How does it select the datasource on which it should open the transaction?

  • Is there some magic trick like proxies, threadlocals or anything?

  • If so, do these tricks work with any JDBC library (for Hibernate it works but what about MyBatis?)

  • What if there are 2 datasources?

  • And what if i’m calling, in a @Transactionnal service, DAO’s with 2 underlying different datasources? Will it be transactionnal for both datasources or just for one of them or will it fail?

Thanks

  • 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-13T00:12:14+00:00Added an answer on June 13, 2026 at 12:12 am

    To use multiple transaction handlers just specifiy a qualifier, and reference it. For two different DAOs with two different datasources, you’ll need two different transaction managers. And of course the transactions should be going on your service classes, not DAO’s directly. Its the same for any type of transactionmanager be it hibernate or plain old jdbc.

    <bean id="transactionManagerOne"
            class="org.springframework.orm.hibernate4.HibernateTransactionManager"
            p:sessionFactory-ref="sessionFactoryOne">
            <qualifier value="One" />
        </bean>
    

    and session factory

    <bean id="sessionFactoryOne"
            class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
            p:dataSource-ref="dataSourceOne"
    

    and just set up a datasource with the ID dataSourceOne, then you cran reference the transactionmanager in code with the qualifier name :

    @Transactional(value = "One")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im using Junit with spring-test and i would like to have a classic transactionnal
We're using Maven/Surefire and Spring/Hibernate transactional tests for a fairly large web application. There
I am using Spring's embedded-database (default DB is HSQLDB) for running some unit tests.
I'm using Hibernate and Spring and I'm currently stuck with something which I thought
I am using Spring Framework transactional annotations for transaction managing and I have an
i have spring project under java, using hibernate query, i like to use pessimistic
I'm using Spring 3.0, and I have a set of methods like this: @Transactional
I am using Sping.Net 1.3.1 and Nhibernate 3.0. I use Spring's Transaction Interceptor in
Is there any performance penalty to define all methods as transactional using Spring AOP
I have a test harness using Spring's SpringJUnit4ClassRunner (which automatically rolls back DB updates

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.