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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:00:50+00:00 2026-06-15T13:00:50+00:00

We have java web application, we are using spring, hibernate3 and I have problem

  • 0

We have java web application, we are using spring, hibernate3 and I have problem with getting actual version of record from DB.

Here is the code snippet:

Class Scheduler
{
    public void scheduleTests(………….)
    {
    .
    .
    .
    TestCase testCase;
    .
    //Updating entity
    getHibernateTemplate ().saveOrUpdate(testCase);
    getHibernateTemplate ().flush();
    .
    .
    .
    Starts new thread
    .
}

Thread run{
    .
    .
    TestCase testCase = getTestCase(testCaseId);
    .
    .
    .
    .
    updateTestCase(testCase);
}

getTestCase(testCaseId)
{
    TestCase testCase = null;
    try
    {                       
        testCase=(TestCase)getHibernateTemplate().get(TestCase.class, testCaseId);
    }
    catch (Exception ex)
    {
       ex.printStackTrace();
    }
    return testCase;
}

updateTestCase(TestCase testCase)
{
    try
    {
       getHibernateTemplate ().saveOrUpdate(testCase);
       getHibernateTemplate ().flush();
    }
    catch (Exception ex)
    {
       ex.printStackTrace();
    }
}

In method schedule test I change the object TestCase and after it is saved into DB. Then new thread starts, and in the beginning of this thread I ask DB for actual version of TestCase from DB. Then some functionality is executed and in the end status of TestCase is updated to DB.

Problem is when I run this scenario more than 1 times. Then weird thing happened. In thread method run I got from method getTestCase old version of TestCase and then update crashes with following exception:

ERROR

org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:300) - Could not synchronize database state with session
"org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [at.h3g.portal.db.webshop.WsRcCheck#405]
    at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1680)
    at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2271)
    at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2180)
    at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2456)
    at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:91)
    at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:988)
    at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:815)
    at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
    at org.springframework.
ERROR org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:300) - Could not synchronize database state with session
"org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [at.h3g.portal.db.webshop.WsRcCheck#405]
    at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1680)
    at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2271)
    at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2180)
    at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2456)
    at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:91)
    at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:988)
    at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:337)
    at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
    at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:584)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:500)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:473)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.doCommitTransactionAfterReturning(TransactionAspectSupport.java:267)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)

Why I got old version of TestCase? What could I do?
Here is configuration of Hibernate and Spring.

In Web.Xml:

<filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    <init-param>
        <param-name>sessionFactoryBeanName</param-name>
        <param-value>sessionFactory</param-value>
    </init-param>
</filter>

And context configuration:

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
        <ref bean="dataSource" />
    </property>
    <property name="mappingResources">
        <list>
        .
        .
        .
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">
                org.hibernate.dialect.Oracle9Dialect
            </prop>
            <prop key="hibernate.connection.release_mode">
                auto
            </prop>
        </props>
    </property>
</bean>

<bean id="dataSource"
    class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName">
        <value>java:comp/env/jdbc/SOMEDATASOURCE</value>
    </property>
</bean>


<bean id="hibernateTemplate"
    class="org.springframework.orm.hibernate3.HibernateTemplate">
    <property name="sessionFactory">
        <ref bean="sessionFactory" />
    </property>
</bean>

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

<bean id="transactionInterceptorTestScheduling"
    class="org.springframework.transaction.interceptor.TransactionInterceptor">
    <property name="transactionManager">
        <ref bean="transactionManager" />
    </property>
    <property name="transactionAttributeSource">
        <value>                 org.company.db.Scheduler.updateTestCase=PROPAGATION_REQUIRES_NEW
        </value>
    </property>
</bean>

And I want to add, there is only one thread created in that time, and nothing else access TestCase data in database. Only problem is that getTestCase returns old version of TestCase record, and I don’t now why.

Thank you for advice.

  • 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-15T13:00:52+00:00Added an answer on June 15, 2026 at 1:00 pm

    Problem is the hibernate session is bounded to the current thread. So one solution is don’t use threads or there should be created transaction interceptor, which will take care about sessions for threads. See more on Spring How to get bean with prototype scope from ProxyFactoryBean

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

Sidebar

Related Questions

I have created a java web application using spring. I want the users of
I have a web application developed using Java (Java EE), spring & Hibernate. We
I have a Java web application using spring web flow. How do I pass
I have a Java Web Application using Spring and running in Glassfish 3.1.2 and
I have java application with web interface (Spring MVC) using Hibernate. I have quite
i have a java web application, using Spring, Jersey (jax-rs) and Hibernate. It runs
I have a Java based web-application using Java Server Faces and Facelets. I am
I have a java web application which I can debug using IntelliJ or Eclipse
I have built a web application using Java EE platform that sells one of
My web application is written using jsp/javascripts. Backend Java. Have managed to implement the

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.