Hibernate lazy-load application design

前端 未结 3 836
闹比i
闹比i 2020-12-12 10:14

I tend to use Hibernate in combination with Spring framework and it\'s declarative transaction demarcation capabilities (e.g., @Transactional).

As we all known, hib

3条回答
  •  忘掉有多难
    2020-12-12 10:38

    A very common pattern is to use OpenEntityManagerInViewFilter if you're building a web application.

    If you're building a service, I would open the TX on the public method of the service, rather than on the DAOs, as very often a method requires to get or update several entities.

    This will solve any "Lazy Load exception". If you need something more advanced for performance tuning, I think fetch profiles is the way to go.

提交回复
热议问题