Announcement Announcement Module
Collapse
No announcement yet.
Spring Hibernate Transaction Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Hibernate Transaction

    Hi,
    I need a help regarding managing transaction. I am using spring/hibernate. I have following layers-
    * Web Service Endpoint
    * Business Service
    * DAO

    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">
    <property name="sessionFactory">
    <ref bean="sessionFactory"/>
    </property>
    </bean>

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

    <tx:annotation-driven/>

    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.

    Problem-
    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.!
    Rakesh

  • #2
    Any help is appreciated.!

    Comment


    • #3
      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).

      Comment


      • #4
        Thanks for the reply. I just read it, earlier i didnt understand spring transaction management properly.

        Comment

        Working...
        X