What does Hibernate.initialize do?

前端 未结 4 1057
遇见更好的自我
遇见更好的自我 2021-01-04 06:19

What does Hibernate.initialize do?
Usually referred documentation talk only about

Hibernate.initialize(entity.lazyCollection)

Is ther

4条回答
  •  执笔经年
    2021-01-04 07:11

    Shortly Hibernate.initialize() creates another query to fetch object in persistence context. When object is loaded eagerly JPA makes only one query to fetch object. So another difference is number calls to server

    In addition : 1. If object is null Hibernate.initialize() throws exception 2. Good source for how to initialize lazy associations http://www.thoughts-on-java.org/5-ways-to-initialize-lazy-relations-and-when-to-use-them/

提交回复
热议问题