Sep 21st, 2010, 01:24 PM
Spring Hibernate Transaction
I need a help regarding managing transaction. I am using spring/hibernate. I have following layers-
* Web Service Endpoint
* Business Service
I extend HibernateDaoSupport in my DAO layer and want to have transaction controlled business method in my business layer. In my spring configuration, i have-
<bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.Hibernat eInterceptor">
<bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
In my business service layer, i define 2 methods-
public JobDetailsTO importAutoeasyjob(Job job)
@Transactional(readOnly=false, propagation=Propagation.REQUIRES_NEW, rollbackFor=Exception.class)
public JobDetailsTO importAutoeasyjobs(List<Job> jobList)
I make multiple importAutoeasyjobs() is a wrapper method which makes multiple calls to importAutoeasyjob() based on size of jobList.
I want whenever an exception occurs in importAutoeasyjob(), it should roll back the whole transaction and throw exception which will be caught in importAutoeasyjob() method. The purpose is, even there is an issue while saving/importing an object, i want to capture the error (in an error list) and process other objects. The problem here is, it commits the transaction only when all objects are processed and before importAutoeasyjobs() method return and exception caused while saving any object, rollsback everything.
For now, i have moved importAutoeasyjobs() to another layer (web service) and moved the code to iterate over jobList and make call to importAutoeasyjob() in business service layer. This works but I would like to move importAutoeasyjobs() also in that layer.
Is there a way, i make sure whenever importAutoeasyjob() returns, the transaction is committed/rollback even if the method is being called from the same layer.
Thanks in advance.!
Sep 21st, 2010, 10:20 PM
Any help is appreciated.!
Sep 22nd, 2010, 01:22 AM
I suggest a read of the AOP chapter. Spring uses proxy based aop and as such internal method calls aren't proxied. If you want transactions either put it in another class or do manual transactionmanagement (with TransactionTemplate).
Sep 22nd, 2010, 01:34 AM
Thanks for the reply. I just read it, earlier i didnt understand spring transaction management properly.
Tags for this Thread