相当于Hibernate.initialize的JPA命令 [英] JPA equivalent command to Hibernate.initialize
问题描述
我有一个Lazy集合,我想在我的服务/控制器中随意初始化.此时,我可以执行以下操作:
I have a Lazy collection that I want to initialize at will in my service/controller. At this moment I can do:
Hibernate.initialize( myEntity.getListOfThings() );
此命令与休眠有关,并且不会使JPA的实现透明.是否有JPA优雅的方式来做到这一点?
This command is hibernate dependent and does not make the implementation of JPA transparent. Is there a JPA elegant way of doing this?
推荐答案
不,没有等效的JPA.您可以了解是否已加载对象而不是使用两个选项之一,要么在对象仍附加到持久性上下文时访问属性,我通常看到的就是调用size,只是为了初始化集合
No, there's no JPA equivalent. You can learn if the object is loaded and than use one of the two options, either accessing the properties while the object is still attached to persistence context, what I typically see is calling size, just for the sake of initializing the collection
myEntity.getListOfThings().size();
或使用查询进行初始化.
or use a query for initialization.
这篇关于相当于Hibernate.initialize的JPA命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!