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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:32:55+00:00 2026-06-04T23:32:55+00:00

Working with MySql replication with spring+hibernate, I have a quick question; The transactions that

  • 0

Working with MySql replication with spring+hibernate, I have a quick question;

The transactions that are opened are in read-only mode i.e pointing to slave DB.
What is the best way to convert it to write mode if I want to save/update/delete any thing during that transaction?

I do not want to open a write mode transaction as most of the time I want read stuff.

Do I need to overide the replication Driver/Hibernate template for this thing?

  • 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-04T23:32:56+00:00Added an answer on June 4, 2026 at 11:32 pm

    We open transactions in read only mode and then convert it to write mode as read only connections will not be an issue as it is with salve DB.

    We override the HibernateTemplate class and create methods to make session in write mode

     public final void writeEnabled(){
        getSession().doWork(jdbcWorkWriteEnabled);
    }
    
    public final void writeDisabled(boolean flush){
        if(flush)
            flush();
        getSession().doWork(jdbcWorkWriteDisabled);
    }
    
    public static final void writeEnabled(Session session){
        session.doWork(jdbcWorkWriteEnabled);
    }
    
    public static final void writeDisabled(boolean flush,Session session){
        if(flush)
            session.flush();
        session.doWork(jdbcWorkWriteDisabled);
    }
    
    final static Work jdbcWorkWriteEnabled = new Work(){
        public void execute(Connection connection) throws SQLException {
            connection.setReadOnly(false);
        }
    };
    
    final static Work jdbcWorkWriteDisabled = new Work(){
        public void execute(Connection connection) throws SQLException {
            connection.setReadOnly(true);
        }
    };
    

    In application logic before write we check
    Connection is in write mode then simply write.
    else if connection is readonly then first make it in write mode, do write operation and again make it back to readonly

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

Sidebar

Related Questions

I have a working mysql query that retrieves data from table1. Now I will
I have read all over the place how WordPress is only capable of working
I have a MySQL database that I'm working with, but when I try to
Any idea why the following code is not working mysql credentials are correct, have
I am working with MySQL version 5. I have two tables structured as shown
I'm working on mysql and have two tables with the same schema: preTrial |id|accusedId|articleid|
I have a dropdown list populated by mysql working perfectly, I also have it
I am working on a MySQL database that is huge (about 120 tables). I
I am working in the mysql console and trying to use a db that
I am working with mysql . I have checked the CREATE table statement ,

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.