Announcement Announcement Module
No announcement yet.
Unable to retrieve data after save or update Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to retrieve data after save or update

    In my application, I am using Spring with Hibernate for persistence.
    I have observed a strange situation, if I save or update an object and then retrive the object immediately, the object is not retrived, but if wait for few seconds after the save or update, the record is retreived properly.
    Did any one of you encountered this situation, if yes can you tell me what needs to be done to correct this issue ?

    I am using spring transaction management and using the propagation type required for save and update operations

     <tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>

  • #2
    where are you loading the entity from? what is your isolation level? can you post entire config and the code where you are saving and loading the entity back?


    • #3
      I have a service class(AreaService), which has methods to get, create or update an Area object.

      Below is the Spring configuration:

      <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
          	<property name="dataSource" ref="locDataSource"/>
      	<tx:advice id="txAdvice" transaction-manager="txManager">
               <tx:method name="get*" read-only="true" rollback-for="java.lang.Exception" />
               <tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
          	<aop:pointcut id="areaServiceOperation" expression="execution(* *.AreaService.*(..))"/>
      <bean id="areaService" class="xxx.xx.AreaService">
      		<property name="areaRepository" ref="areaRepository" />
      In the AreaService class, I call the area Repository, which uses HibernateTemplate to save or update the Area object.

      below are the hibernate properties in the hibernate configuration file

      <property name="hibernateProperties">
      				<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
      				<prop key="hibernate.show_sql">true</prop>
      				<prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</prop>
      				<prop key="hibernate.format_sql">true</prop>
      				<prop key="hibernate.cache.use_query_cache">false</prop>
      				<prop key="hibernate.cache.query_cache_factory">org.hibernate.cache.StandardQueryCacheFactory</prop>
      				<prop key="hibernate.cache.use_second_level_cache">false</prop>
      				<prop key="hibernate.cache.use_structured_entries">false</prop>
      				<prop key="hibernate.cache.use_minimal_puts">false</prop>
      				<prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</prop>
      Code to save or update the business object
       public void saveOrUpdateBusinessObject(final Base businessObject) {
      I have a Junit test class, which first creates an Area object and then I retreive the object for validation. I observed that the get method doesn't return the Area object immediately after save(). But, if I put Thread.sleep() between the Save and retreive, I am able to get the new object.


      • #4
        I found why I was not able to retrieve the data immediately, I was using HibernateTemplate for saving the data and Spring Jdbc template for retreiving the data. If I stick to any one of these for saving and retreiving it works fine.
        Last edited by tsurya; Feb 18th, 2010, 08:10 AM.