项目中使用到hibernate5,在one-to-one 及many-to-one时,发现不是懒加载。
通过ide自动生成发现如下:
默认改为急切加载了?
于是查看hibernate5.2文档
The Hibernate recommendation is to statically mark all associations
lazy and to use dynamic fetching strategies for eagerness. This is
unfortunately at odds with the JPA specification which defines that
all one-to-one and many-to-one associations should be eagerly fetched
by default. Hibernate, as a JPA provider, honors that default.
发现以上说明,意思是hibernate默认都是懒加载,但是jpa2对于一对一和多对一情况下,默认使用迫切加载,两者有冲突。
hibernate作为jpa的实现者,从了。保持跟jpa2一致。
以上。