How do I properly do a background thread when using Spring Data and Hibernate?

后端 未结 3 750
小鲜肉
小鲜肉 2020-11-28 11:00

I\'m building a simple Tomcat webapp that\'s using Spring Data and Hibernate. There\'s one end point that does a lot of work, so I want to offload the work to a background t

3条回答
  •  一个人的身影
    2020-11-28 11:20

    What happens is, probably, you have transaction on your DAO piece of code and Spring is closing the session on transaction close.

    You should squeeze all your business logic into single transaction.

    You can inject SessionFactory into your code and use SessionFactory.openSession() method.
    The problem is, that you will have to manage your transactions.

提交回复
热议问题