Spring OpenSessionInViewFilter with @Transactional annotation

前端 未结 4 1448
一向
一向 2020-12-31 12:30

This is regarding Spring OpenSessionInViewFilter using with @Transactional annotation at service layer.

i went through so many stack overf

4条回答
  •  北海茫月
    2020-12-31 12:49

    OpenSessionInViewFilter is a servlet filter that binds a hibernate session to http request and for all db operations, transactional and non transactional, same hibernate session is used for a given http request. This exposes db layer to web layer that makes it anti-pattern.

    My experience is that this makes the code difficult to debug when we want to make changes to java objects and do not want those to get reflected in database. Since the hibernate session is always open, it expects to flush the data in database.

    This should be used only when JS base rest services are there with no service layer in between.

提交回复
热议问题