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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:00:22+00:00 2026-05-25T20:00:22+00:00

We are refactoring a legacy application. The old code did something like this in

  • 0

We are refactoring a legacy application. The old code did something like this in a Controller method:

  • Call DAO1.update()
  • Call DAO2.update()

We’ve placed an in between a service layer, so the above code now looks like:

  • Call Service1.update() –> Call DAO1.update()
  • Call Service2.update() –> Call DAO2.update()

Each of the above two update methods have been marked transactional (using spring transactions). Old code didn’t handle transactions that well – now, we want a user action (controller method) to map only to a single transaction. How can we achieve that using spring transactions itself?

PS:

  1. We did checked Hibernate’s Open Session in View pattern, but we
    would like a solution that makes use of Spring transactions – the
    above scenarios are not that common and we are worried about
    performance decay in OSIV pattern.
  2. We can combine the two service methods above into a single method but would welcome a bit cleaner situation that won’t hinder reuse.
  • 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-05-25T20:00:23+00:00Added an answer on May 25, 2026 at 8:00 pm

    If you want to keep using the @Transactional annotation, then you sure have to wrap your calls in a broader, annotated method. So, either you define business services, which may become quite boilerplate/redundant indeed, or you make your controller’s handling method transactional itself (as a @Component it is a Spring-managed bean so you can use @Transactional there too), or you define a flexible, generic, callback-based template:

    @Component
    public class TxWorker {
        @Transactional
        public <T> T doInTx(Callable<T> callback) throws Exception {
            return callback.call();
        }
    }
    

    The drawback of the latter is that it may become a bit messy if you overuse it.

    Note that you may combine the OpenSessionInView pattern and Spring-managed transactions, since the Hibernate session (or JPA entityManager) may span across many tx (see What is the difference between Transaction-scoped Persistence context and Extended Persistence context?). But its main goal is to provide lazy-loading while rendering views, so it is not exactly what you’re looking for.

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

Sidebar

Related Questions

I'm refactoring some legacy code, and I keep running into this Object. I would
Doing some refactoring in some legacy code I've found in a project. This is
I am refactoring some legacy code. The app was not using querystrings. The previous
While refactoring my code base I found a piece of code which I'd like
I'm refactoring some code and would like to junit test some methods but they
I just had this throw a compilation error while refactoring some legacy (hence VB.NET)
I'm working on some refactoring of legacy code to move styles to a stylesheet
I have a collection of legacy C code which I'm refactoring to split the
I am refactoring a legacy application where the actual application is scattered in between
I inherited some legacy Java (1.4) code and this design decision appears regularly. I

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.