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 8293817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:57:52+00:00 2026-06-08T13:57:52+00:00

Firstly, I can’t use the declarative @Transactional approach as the application has multiple JDBC

  • 0

Firstly, I can’t use the declarative @Transactional approach as the application has multiple JDBC data-sources, I don’t want to bore with the details, but suffice it to say the DAO method is passed the correct data-source to perform the logic. All JDBC data sources have the same schema, they’re separated as I’m exposing rest services for an ERP system.

Due to this legacy system there are a lot of long lived locked records which I do not have control over, so I want dirty reads.

Using JDBC I would perform the following:

private Customer getCustomer(DataSource ds, String id) {
    Customer c = null;
    PreparedStatement stmt = null;
    Connection con = null;
    try {
        con = ds.getConnection();
        con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
        stmt = con.prepareStatement(SELECT_CUSTOMER);
        stmt.setString(1, id);
        ResultSet res = stmt.executeQuery();
        c = buildCustomer(res);
    } catch (SQLException ex) {
        // log errors
    } finally {
        // Close resources
    }
    return c;
}

Okay, lots’ of boiler-plate, I know. So I’ve tried out JdbcTemplate since I’m using spring.

Use JdbcTemplate

private Customer getCustomer(JdbcTemplate t, String id) {
    return t.queryForObject(SELECT_CUSTOMER, new CustomerRowMapper(), id);
}

Much nicer, but it’s still using default transaction isolation. I need to somehow change this. So I thought about using a TransactionTemplate.

private Customer getCustomer(final TransactionTemplate tt,
                             final JdbcTemplate t,
                             final String id) {
    return tt.execute(new TransactionCallback<Customer>() {
        @Override
        public Customer doInTransaction(TransactionStatus ts) {
            return t.queryForObject(SELECT_CUSTOMER, new CustomerRowMapper(), id);
        }
    });
}

But how do I set the transaction isolation here? I can’t find it anywhere on the callback or the TransactionTemplate to do this.

I’m reading Spring in Action, Third Edition which explains as far as I’ve done, though the chapter on transactions continues on to using declarative transactions with annotations, but as mentioned I can’t use this as my DAO needs to determine at runtime which data-source to used based on provided arguments, in my case a country code.

Any help would be greatly appreciated.

  • 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-08T13:57:54+00:00Added an answer on June 8, 2026 at 1:57 pm

    I’ve currently solved this by using the DataSourceTransactionManager directly, though it seems like I’m not saving as much boiler-plate as I first hoped. Don’t get me wrong, it’s cleaner, though I still can’t help but feel there must be a simpler way. I don’t need a transaction for the read, I just want to set the isolation.

    private Customer getCustomer(final DataSourceTransactionManager txMan,
                                 final JdbcTemplate t,
                                 final String id) {
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED);
    
        TransactionStatus status = txMan.getTransaction(def);
        Customer c = null;
        try {
            c = t.queryForObject(SELECT_CUSTOMER, new CustomerRowMapper(), id);
        } catch (Exception ex) {
            txMan.rollback(status);
            throw ex;
        }
        txMan.commit(status);
        return c;
    }
    

    I’m still going to keep this one unanswered for a while as I truly believe there must be a better way.

    Refer to Spring 3.1.x Documentation – Chapter 11 – Transaction Management

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

Sidebar

Related Questions

I want to parse JSON arrays and using gson. Firstly, I can log JSON
Firstly, can anyone explain how a state object can be shared when the state
Firstly, what i am trying to do is have a page that users can
Firstly I've looked at a lot of posts on Stackoverflow but I don't see
Firstly, I have found many examples of how to grab data from a db
Firstly, this is for a class so there are limitations on what we can
Firstly I want to say I know little english. I have seeking about this
Firstly, I'm making a web application, not an iPhone application. How do you open
Firstly, please don't move to serverfault. It is indeed a programming question :-) We
There are two parts to my question - Firstly we can attach event handlers

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.