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

前端 未结 6 1592
温柔的废话
温柔的废话 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:23

    When you leave a session open that has read some data, you will leave that transaction open. Long running transactions aren't that big of a problem (although that might depend on your database) what really causes problems are locks hold for a long time, but these might only get created once you actually change data in the database. Again this depends on your database.

提交回复
热议问题