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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:25:25+00:00 2026-06-07T09:25:25+00:00

Situation – Story time: I inherited a program, a rather simple webservice for accessing

  • 0

Situation – Story time:
I “inherited” a program, a rather simple webservice for accessing a databse. This program had a flaw somewhere: It tried to update a table it had no update grant for. The program has only the right to update a Database Queue (Oracle), to save information who accessed what. This was undesired behaviour, and by now I fixed it. Note: This is not relevant to this question per se, its just the cause that led me to this question.

The program uses Spring + Hibernate for managing and accessing the data and the transactions.

Because the program is in high demand and the error was deemed intolerable, I had the quick idea to add a hotfix, simply to force a rollback on each transaction until I find the part of the software that actually manipulates data it should not manipulate.

The software uses 2 @Transactional annotations. One over the whole process, and another on the part thats writing the log data. This second one was used with the Requires_New propagation setting. As far as I understood it, this second one would always create a new Transaction and flush it when its span (in this case: one method) was over.

I then added a direct Rollback-Statement TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); after the nested transaction was already over, to rollback the outer transaction (therefor undoing the manipulation). But it didn’t work that way. Both transaction were rolled back. Can anyone give me any pointers to why this happened? Its kinda conflicting what I thought I knew how the system works. Does currentTransactionStatus() include ALL transactions associated with the current session?

Relevant Code snippet (shortend for clarity)

@Override
@Transactional
@PreAuthorize(Rollen.INFOVN)
public InfoVNAntwort infoVNAnfrage(final InfoVNAnfrage infoVNAnfrage) {

    // extract data from request
    final InfoVNDatenhalter datenhalter = (InfoVNDatenhalter) this.getController().erzeugeNeuenDatenhalter(ProzessNamen.INFOVN);
    datenhalter.setAnfrageFin(StringUtils.trimToNull(infoVNAnfrage.getFIN()));
    datenhalter.setAnfrageZB2(StringUtils.trimToNull(infoVNAnfrage.getZB2()));
    final String username = this.getCurrentUserName();
    datenhalter.setBenutzerkennung(username);
    datenhalter.setErgaenzungstext(infoVNAnfrage.getErgaenzungstext());
    datenhalter.setAnfragegrund(infoVNAnfrage.getAnfrageanlass());

    // actual fetch of database data
    final DialogAntwort da = (DialogAntwort) this.getController().verarbeite(datenhalter);

    // convert to ws response
    final InfoVNAntwort vnAntwort = this.getMapper().map(da, InfoVNAntwort.class);

    // log who did what
    this.erstelleBewirt(vnAntwort, infoVNAnfrage, new DateTime(), username);

    // roll back outer transaction
    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();

    return vnAntwort;
}

@Transactional(propagation = Propagation.REQUIRES_NEW)
private void erstelleBewirt(final InfoVNAntwort vnAntwort, final InfoVNAnfrage infoVNAnfrage, final DateTime zeitpunktAuskunft, final String username) {
    final InfoVNBewirt eintrag = new InfoVNBewirt();
    eintrag.setZeitpunktErteilungAuskunft(zeitpunktAuskunft);
    eintrag.setSteuerelement(STEUERELEMENT_INFOVN);
    eintrag.setAnfrageAnlass(infoVNAnfrage.getAnfrageanlass());
    this.completeEintrag(username, eintrag);
    this.logdatenPersister.persistiereLogdaten(eintrag);
}

Database-Connection:

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="packagesToScan">
            <list>
                <value>de.mm.vwn</value>
                <value>de.mm.cfo.allgemein.kenauthent</value>
                <value>de.mm.cfo.infovn.logdaten</value>
            </list>
        </property>
        <property name="hibernateProperties" ref="hibernateProperties"></property>
    </bean>

    <bean id="hibernateProperties"
        class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="properties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.hbm2ddl.auto">none</prop>
                <prop key="hibernate.show_sql">false</prop>
                <prop key="hibernate.format_sql">false</prop>
                <prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</prop>
<prop key="hibernate.jdbc.use_scrollable_resultset">true</prop>
<prop key="hibernate.jdbc.batch_size">25</prop>
            </props>
        </property>
    </bean>

    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="dataSource" ref="dataSource" />
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>

    <tx:annotation-driven />
  • 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-07T09:25:26+00:00Added an answer on June 7, 2026 at 9:25 am

    OK. The problem is the one I thought.

    Here’s how Spring makes beans transactional: when you get a transactional bean from the Spring bean factory, or thanks to dependency injection, Spring doesn’t give you an instance of your bean class. It gives you a proxy which has the same interface as your bean class, and delegates all the method calls to an instance of your bean class, except it starts a transaction (if needed) before invoking the method, and rollbacks/commits the transaction (if needed) after the method has returned:

    Client ----> transactional proxy ----> bean.infoVNAnfrage()
    

    If, from your bean class instance (InfoVNAntwort), you call another method of the same bean, the method invocation doesn’t go through the proxy:

    Client ----> transactional proxy ----> bean.infoVNAnfrage() ----> bean.erstelleBewirt()
    

    So Spring has no way to start a new transaction for erstelleBewirt().

    The easier way is to put the erstelleBewirt() method into another transactional Spring bean, and to inject this other Spring bean into your current bean:

    Client ----> transactional proxy ----> bean.infoVNAnfrage() ----> transactional proxy ----> otherBean.erstelleBewirt()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Situation is simple: I post a plain HTML form with a textarea. Then, in
Situation: I often run into this problematic and never know how to solve it.
Situation is simple. I need to wrap text around two inline objects (buttons with
Situation: I am writing a program in C that maintains a number of threads.
Situation I'd like to make an RPC interface easier to use. This is a
Situation: I am writing a program to solve for primes. I need to solve
Situation: I am working on a Qt4 application constructed in this way (in case
Situation: I have a multithreaded program written in C. If one of the threads
Situation According to this accepted answer , if the " GC 'sees' a cyclic
Situation: I have a simple XML document that contains image information. I need to

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.