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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:40:57+00:00 2026-06-13T07:40:57+00:00

I have created an integration test of a service that is not rolling back

  • 0

I have created an integration test of a service that is not rolling back the transaction after completion. I know this from looking at the db and from my the error I get when I run the test a second time. I’ve been googling this issue all morning and feel I have everything set properly. This is a hibernate/jpa app writing to SQLServer 2008. I am not sure where else to look. Snippet below.

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
        DependencyInjectionTestExecutionListener.class,
        DirtiesContextTestExecutionListener.class,
        TransactionalTestExecutionListener.class })
@TransactionConfiguration(defaultRollback=true)
@Transactional // extend transactional boundary to test class so that automatic rollback works properly
@ContextConfiguration(locations = {
        "file:./src/main/resources/AghostMobile.Service-business.service-context.xml",
        "file:./src/main/resources/AghostMobile.Service-service-context.xml",
        "file:./src/main/resources/AghostMobile.Service-dao-context.xml"})
public class ColorSchemeMigrationServiceIntTest {

    /**
     * The service being tested, injected by Spring
     *
     */
    @Autowired
    ColorSchemeMigrationService service;

    /**
     * The helper services, injected by Spring.
     *
     */
    @Autowired
    protected WebsitecolorpaletteuserdefinedService userPaletteService;
    @Test
    public void testSaveColorPalette() {
        Integer mobileWebsiteId = Integer.valueOf(386);
        Integer custId = Integer.valueOf(15);
        Integer siteId = Integer.valueOf(2);
        String user = "Test";

        Websitecolorpaletteuserdefined palette = service.translateColorScheme(mobileWebsiteId, custId, siteId, user);

        service.saveColorPalette(palette);

        Websitecolorpaletteuserdefined response = userPaletteService.findWebsitecolorpaletteuserdefinedByCustIdAndSiteId(custId, siteId);

        assertNotNull("User palette not found.", response);
        assertEquals("CustId is not the expected value.", custId, response.getCustId());
        assertEquals("SiteId is not the expected value.", siteId, response.getSiteId());
    }

Currently, I have the following beans defined:

<!-- ******************************************************************** -->
<!-- Setup the transaction manager -->
<!-- ******************************************************************** -->
    <!-- Using Atomikos Transaction Manager -->
    <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init"
        destroy-method="close">
        <property name="forceShutdown" value="true" />
        <property name="startupTransactionService" value="true" />
        <property name="transactionTimeout" value="60" />
    </bean>

    <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp" />
    <!-- Configure the Spring framework to use JTA transactions from Atomikos -->
    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
        <property name="transactionManager" ref="atomikosTransactionManager" />
        <property name="userTransaction" ref="atomikosUserTransaction" />
        <property name="transactionSynchronizationName" value="SYNCHRONIZATION_ON_ACTUAL_TRANSACTION" />
    </bean>
<!-- ******************************************************************** -->
<!-- Setup a data source -->
<!-- ******************************************************************** -->
<!-- Using Apache DBCP Data Sources -->
<bean name="hostDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" >
    <property name="driverClassName" value="${My_JDTs_to_AgHost_Host_scheme.connection.driver_class}" />
    <property name="username" value="${My_JDTs_to_AgHost_Host_scheme.connection.username}" />
    <property name="password" value="${My_JDTs_to_AgHost_Host_scheme.connection.password}" />
    <property name="url" value="${My_JDTs_to_AgHost_Host_scheme.connection.url}" />
    <property name="maxIdle" value="${My_JDTs_to_AgHost_Host_scheme.minPoolSize}" />
    <property name="maxActive" value="${My_JDTs_to_AgHost_Host_scheme.maxPoolSize}" />
</bean>

<!-- ******************************************************************** -->
<!-- Setup each persistence unit -->
<!-- ******************************************************************** -->
            <!-- Configure a JPA vendor adapter -->
            <bean id="My_JDTs_to_AgHost_Host_schemeJPAVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="${My_JDTs_to_AgHost_Host_scheme.show_sql}" />
                <property name="generateDdl" value="${My_JDTs_to_AgHost_Host_scheme.generateDdl}" />
                <property name="databasePlatform" value="${My_JDTs_to_AgHost_Host_scheme.dialect}" />
            </bean>
            <!-- EntityManager Factory that brings together the persistence unit, datasource, and JPA Vendor -->
            <bean id="My_JDTs_to_AgHost_Host_scheme" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                <property name="dataSource" ref="hostDataSource" />
                <property name="persistenceUnitName" value="My_JDTs_to_AgHost_Host_scheme" />
                <property name="jpaVendorAdapter" ref="My_JDTs_to_AgHost_Host_schemeJPAVendorAdapter" />
                    <property name="jpaPropertyMap">
                        <map>
                                    <entry key="hibernate.transaction.manager_lookup_class" value="com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup" />
                                    <!-- <entry key="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory" /> -->
                                    <entry key="hibernate.connection.release_mode" value="on_close" />
                        </map>
                    </property>
            </bean>

This does allow me to update my data, but does not rollback my transaction. So, I am using a transaction manager, org.springframework.jdbc.datasource.DataSourceTransactionManager. I replaced the three beans in the “Setup transaction manager” block with:

    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="hostDataSource" />
    </bean>

This left me with tests failing with IllegalStateException: This method needs a transaction for the calling thread and none exists. The exception also stated:

Possible causes: either you didn't start a transaction,
it rolledback due to timeout, or it was committed already.
ACTIONS: You can try one of the following: 
1. Make sure you started a transaction for the thread.
2. Make sure you didn't terminate it yet.
3. Increase the transaction timeout to avoid automatic rollback of long transactions;
   check [http://www.atomikos.com/Documentation/JtaProperties][1] for how to do this.

I’ll admit to not having read that document yet and will do so after posting these updates. I have also found this thread, which looked promising: persistence-unit, different hibernate.transaction.manager_lookup_class property. You can see that commented out in bean My_JDTs_to_AgHost_Host_scheme. This failed pretty miserably. But, perhaps I didn’t use it properly.

I also found this thread: Spring/JTA/JPA DAO integration test doesn't rollback?. This looks quite promising, but again I am not sure how to use what it is telling me.

  • 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-13T07:40:58+00:00Added an answer on June 13, 2026 at 7:40 am

    The answer tunred out to be found here: Spring/JTA/JPA DAO integration test doesn't rollback?. I changed the datasource to the following.

    <bean name="hostDataSource" class="com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean" destroy-method="close" >
        <property name="driverClassName" value="${My_JDTs_to_AgHost_Host_scheme.connection.driver_class}" />
        <property name="user" value="${My_JDTs_to_AgHost_Host_scheme.connection.username}" />
        <property name="password" value="${My_JDTs_to_AgHost_Host_scheme.connection.password}" />
        <property name="url" value="${My_JDTs_to_AgHost_Host_scheme.connection.url}" />
    
        <property name="maxPoolSize" value="20" />
        <property name="reapTimeout" value="300" />
        <property name="uniqueResourceName" value="myappDatabase" />
    </bean>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an integration test using the White automation framework. This is the
I have created a service that communicates with the SalesForce platform via C#, using
I have an integration test which initialize a test wcf service host in code.
I have several integration tests for various services that extend the following baseclass: @ContextConfiguration(locations=classpath:applicationContext-test.xml)
I am trying to authenticate inside integration test by calling FormsAuthentication.SetAuthCookie(someUser, false); After that
I am using the latest version of protobuf-net with VS2008 integration. I have created
I have a class that creates a file. I am now doing integration tests
I have created 3 classes as following Ext.mine.TextParent - Inherting from Textfield Ext.mine.child.TextChildA -
I have created some JQuery that will expand a div 'popup' on hover and
I have created an android application that calls (using kSOAP library) a SOAP based

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.