In my application, hibernate transactions are managed by spring aop and uses Terdata as database.
THIS ISSUES IS SPECIFIC TO TERADATA AND THE SAME CODES WORKS FINE IN MYSQL.
There is one service class i.e. ServiceClass.
It has method called save which takes list of objects as parameters and checks whether it is modified or not by checking it with data from database.
After that it calls the DAO class which persist the data in database.
ServiceClass method's aop:
<tx:advice id="txAdviceForService" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="save" isolation="READ_COMMITTED"/> </tx:attributes> </tx:advice>
ServiceClass:
public void save(List<Test> testList) { DAOClass daoClass;
boolean isUpdated = false ; for (Test test : testList) { Test testInDB = this.sessionFactory.getCurrentSession().get( Test.class, test.getId()); if(! test.getName().equals(testIndDB)) { isUpdated = true ; break; } } daoClass.save(testList);
if(isUpdated) { // do some processing } }
DAOClass:
public void save(List<Test> testList) {
for (Test test : testList) { try { this.sessionFactory.getCurrentSession().saveOrUpdate(test); session.flush(); } catch (HibernateException e) { /// } }
}
DAOClass method's aop: <tx:advice id="txAdviceForDAO" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="save" propagation="REQUIRES_NEW" /> </tx:attributes> </tx:advice>
Transaction management code: <aop:config> <aop:advisor advice-ref="txAdviceForService" pointcut="execution(* ServiceClass.*(..))" /> <aop:advisor advice-ref="txAdviceForDAO" pointcut="execution(* DAOClass.*(..))" /> </aop:config>
Here, when service class calls save method of DAO class, it starts in new transaction as mentioned above in AOP code..
The issue is service class reads object from database in one transaction and then it calls method which starts a new transaction to save data. When it calls session.flush, the table gets locked and can't get accessed even from outside application and the application gets hanged.
If i put the code of saving data from DAO to service class then it works fine as because it is under same transaction.
Has any body face similar issue while using Hibernate with Teradata (with spring managed transaction) ?
Regards,
Chirag
|