JPA equivalent command to Hibernate.initialize

别等时光非礼了梦想. 提交于 2019-12-07 19:06:16

问题


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() );

This command is hibernate dependent and does not make the implementation of JPA transparent. Is there a JPA elegant way of doing this?


回答1:


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.



来源:https://stackoverflow.com/questions/29368563/jpa-equivalent-command-to-hibernate-initialize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!