I have a service class(AreaService), which has methods to get, create or update an Area object.
Below is the Spring configuration:
Code:
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="locDataSource"/>
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true" rollback-for="java.lang.Exception" />
<tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="areaServiceOperation" expression="execution(* *.AreaService.*(..))"/>
</aop:config>
<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
Code:
<property name="hibernateProperties">
<props>
<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>
</props>
</property>
Code to save or update the business object
Code:
public void saveOrUpdateBusinessObject(final Base businessObject) {
this.getHibernateTemplate().saveOrUpdate(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.