Hibernate spring annotation sessions not being closed/flushed

后端 未结 4 1819
情书的邮戳
情书的邮戳 2021-01-07 08:04

I\'ve \'inherited\' a project which uses Spring annotations to manage transactions/sessions with Hibernate. Or at least it\'s meant to be. Currently the Hibernate sessions n

4条回答
  •  一整个雨季
    2021-01-07 08:38

    One of my cleverer colleagues discovered what the problem was.

    The actual problem was that the method that you've declared as @Transactional is an inherited method that is called from a base class, which means that Spring is unable to intercept calls to the method and wrap it in a transaction.

    Spring implements transaction management as aspects, and aspects are implemented with proxies. The limitation of this is that if an object calls a method on itself (which is what's happening here because of inheritance) then the proxy doesn't see the call (because it happens internally within the class, like calling a private method), and can't so anything about it.

    Which makes sense but seems to be incredibly dangerous as it fails to write any data without any error message or warning.

提交回复
热议问题