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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:17:03+00:00 2026-05-27T15:17:03+00:00

I have this non standard situation where i need to update object inside readOnly

  • 0

I have this non standard situation where i need to update object inside readOnly Hibernate transaction. The thing is, i load many other objects, change them within that transaction, but only one should be saved, rest roll-backed. The database i work on is Postgresql 8.4

I`m not sure i understand docs correctly, but making a service method:

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)

should result in opening new RW transaction explicitly for that save.

The main thing is, this is not working:

@Transactional(readOnly = true)
public class PersonService {

    @Resource(name="sessionFactory")
    private SessionFactory sessionFactory;

    public void add(Person person){

        person.setFirstName("changed its name");
        save(person);
    }

    @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
    public void save(Person person) {

        Session session = sessionFactory.getCurrentSession();

        session.save(person);
        session.flush();
    }
}

After that i get

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update

From controller, call the ‘add’ method. ‘add’ is in readOnly mode, and it passes the Person object to ‘save’ method, which should open new Transaction and save to DB. In my project in the ‘add’ method i have many other ‘Person’ objects loaded, which should not be saved.
The reason i need the method to be readOnly is that i load many more objects farther in code 🙂 Rolling them back is last thing i want to do.

Is it possible to do that this way?

  • 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-27T15:17:04+00:00Added an answer on May 27, 2026 at 3:17 pm

    Transactions are typically applied by generating an implementation for a service interface (you don’t show that you’re implementing an interface, that might just be your example code?)

    Anyway, the point is that in that case, simply calling save(…) is not going through the wrapper, it’s just running the method on the target object. You would need to inject a reference from the service to itself, so it could call itself and get the wrapping applied. That is:

    public class PersonServiceImpl implements PersonService {
      PersonService personService;
      public void readOnlyMethod() {
        // ...
        personService.readWriteMethod(...);
      }
      public void readWriteMethod(...) {
      }
    }
    

    And the call stack would look something like:

    PersonServiceImpl.readWriteMethod(...)
    TransactionAroundAdvice.advise(...) // starts/ends new read-write transaction
    $Proxy.readWriteMethod(...) // implementing PersonService
    PersonServiceImpl.readOnlyMethod(...)
    TransactionAroundAdvice.advise(...) // starts/ends read-only transaction
    $Proxy.readOnlyMethod(...) // implementing PersonService
    ClientCode.doSomethingNotReallyReadOnly(...)
    

    (what you’re describing sounds like logging an error message of some sort, which is where I’ve used requiresNew transaction marking (in J2EE though, but I think the point carries))

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

Sidebar

Related Questions

I have text with alot of non-standard characters and they are stored like this
I have this href link with text either attivo or non attivo User can
how exactly I can use public methods (non-virtual) with NHibernate? I have this code:
I currently have a query that looks like this: SELECT NON EMPTY ([Measures].[TOTAL]) ON
I have non-template class with a templatized constructor. This code compiles for me. But
I'm not sure if this is possible (complete non-flash developer speaking), but we have
I have this idea for a free backup application. The largest problem I need
I have this gigantic ugly string: J0000000: Transaction A0001401 started on 8/22/2008 9:49:29 AM
I have a situation where I need to generate a table from a stored
I have created a non standard shaped window with the WindowStyle=None AllowsTransparency=True Background=Transparent approach.

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.