Open Session In View Pattern

前端 未结 6 1126
既然无缘
既然无缘 2020-11-27 17:25

I\'m asking this question given my chosen development frameworks of JPA (Hibernate implementation of), Spring, and

6条回答
  •  忘掉有多难
    2020-11-27 18:15

    I have successfully used the Open-Session-in-View pattern on a project. However, I recently read in "Spring In Practice" of an interesting potential problem with non-repeatable reads if you manage your transactions at a lower layer while keeping the Hibernate session open in the view layer.

    We managed most of our transactions in the service layer, but kept the hibernate session open in the view layer. This meant that lazy reads in the view were resulting in separate read transactions.

    We managed our transactions in our service layer to minimize transaction duration. For instance, some of our service calls resulted in both a database transaction and a web service call to an external service. We did not want our transaction to be open while waiting for a web service call to respond.

    As our system never went into production, I am not sure if there were any real problems with it, but I suspect that there was the potential for the view to attempt to lazily load an object that has been deleted by someone else.

提交回复
热议问题