Announcement Announcement Module
No announcement yet.
Hibernate, Spring Web Service transaction issue. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate, Spring Web Service transaction issue.

    Hi all,
    I have two applications. One is OrderService and another is TradeService.
    In trade service there is a method 'Buy' which is transactional.

    Issue arises when Trade Service calls SubmitOrder method of Order service using Web Service.

    Description of Issue:

    1. All steps in Buy method are under one transaction.

    2. When we call buy method it creates one session.

    3. When this method calls Submit Order method using web service, It passes order Id.

    4. Submit Order method use this Id to load Order Object from DB.

    5. But in Load method It gives Lazy Initialization Exception: Session is closed.
    - Reason behind this, as we call submit order through web service, the transaction is associated with Trade service and not Order service.

    6. Probable solution to this is make Submit Order method transactional.

    7. It leads to another Deadlock issue.
    - Reason for deadlock,
    A. Buy method Locks Order Object with Id say 'xyz'. and sends same Id to submit order method.
    B. Now Buy method is waiting for reply from submit order.
    C. Submit Order method can not load order Object as it is already locked by buy method.
    D. So Submit Order method is waiting to acquire lock. Hence it is dead lock condition.

    Note: Application uses Spring MVC, Spring Web Service and Hibernate.