In Spring with jpa/hibernate, how do I keep a session open to avoid lazy initialization exceptions?

前端 未结 6 1591
温柔的废话
温柔的废话 2020-12-02 14:52

I currently mark collections in entity beans as eager to avoid getting a lazy initialization exception when I try to access the collection properties after loading the bean

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 15:13

    Now, I haven't used Spring, but I have used Hibernate in several different projects. The approach I settled on for the most recent project grew out of the Defensive Session Handling pattern (in conjunction with a servlet filter), and we are happy with it. You can find more design patterns here.

提交回复
热议问题