Multiple transactions in a single hibernate session (with Spring)

前端 未结 2 813
被撕碎了的回忆
被撕碎了的回忆 2021-02-05 20:04

Is it possible to model the following using Hibernate + Spring.

  • Open session
  • Begin transaction
  • Do some work
  • Commit
  • Begin transa
2条回答
  •  温柔的废话
    2021-02-05 21:05

    You could achieve this using the OpenSessionInView pattern. Spring provides a javax.servlet.Filter implementation which you could use if you're working in a servlet environment (question doesn't say so). This will ensure that your Hibernate session is kept open for the duration of the request rather than just for an individual transaction.

    The Javadoc on this class is pretty comprehensive and might be a good starting point.

提交回复
热议问题