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

The Archive Base Latest Questions

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

My application loads entities from a Hibernate DAO, with OpenSessionInViewFilter to allow rendering. In

  • 0

My application loads entities from a Hibernate DAO, with OpenSessionInViewFilter to allow rendering.

In some cases I want to make a minor change to a field –

Long orderId ...

link = new Link("cancel") {
    @Override public void onClick() {
        Order order = orderDAO.load(orderId);
        order.setCancelledTime(timeSource.getCurrentTime());       
    };

but such a change is not persisted, as the OSIV doesn’t flush.

It seems a real shame to have to call orderDOA.save(order) in these cases, but I don’t want to go as far as changing the FlushMode on the OSIV.

Has anyone found any way of declaring a ‘request handling’ (such as onClick) as requiring a transaction?

Ideally I suppose the transaction would be started early in the request cycle, and committed by the OSIV, so that all logic and rendering would take place in same transaction.

  • 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-22T16:14:26+00:00Added an answer on May 22, 2026 at 4:14 pm

    Disclaimer : I’ve never actually tried this, but I think it would work. This also may be a little bit more code than you want to write. Finally, I’m assuming that your WebApplication subclasses SpringWebApplication. Are you with me so far?

    The plan is to tell Spring that we want to run the statements of you onClick method in a transaction. In order to do that, we have to do three things.

    Step 1 : inject the PlatformTransactionManager into your WebPage:

    @SpringBean
    private PlatformTransactionManager platformTransactionManager;
    

    Step 2 : create a static TransactionDefinition in your WebPage that we will later reference:

    protected static final TransactionDefinition TRANSACTION_DEFINITION;
    static {
        TRANSACTION_DEFINITION = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
        ((DefaultTransactionDefinition) TRANSACTION_DEFINITION).setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE);
    }
    

    Feel free to change the TransactionDefinition settings and/or move the definition to a shared location as appropriate. This particular definition instructs Spring to start a new transaction even if there’s already one started and to use the maximum transaction isolation level.

    Step 3 : add transaction management to the onClick method:

    link = new Link("cancel") {
        @Override 
        public void onClick() {
            new TransactionTemplate(platformTransactionManager, TRANSACTION_DEFINITION).execute(new TransactionCallback() {
                @Override
                public Object doInTransaction(TransactionStatus status) {
                    Order order = orderDAO.load(orderId);
                    order.setCancelledTime(timeSource.getCurrentTime());      
                }
            }
        } 
    };
    

    And that should do the trick!

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

Sidebar

Related Questions

My application loads an XML data set from a file on disk using serialization,
My ASP.NET application loads an assembly and creates a class instance from an object
My application dynamically loads assemblies at runtime from specific subfolders. These assemblies are compiled
My application is using Self-Tracking Entities & I get my data from a WCF
I want to load test data in my scala play application from data.yml file
I want to allow users of a asp.net mvc 2 application, creating dynamicly reports.
I'm creating a splash screen that will display while my Android application loads. I'd
My application uses loads of Java threads. I am looking for a reliable understanding
I have an application that loads external SWF files and plays them inside a
I have an application which loads up c# source files dynamically and runs them

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.