Java 如何通过hibernate映射知道延迟加载是否有效?
我有一个包含5列的Person对象,我使用了以下属性:Java 如何通过hibernate映射知道延迟加载是否有效?,java,hibernate,hql,hibernate-mapping,Java,Hibernate,Hql,Hibernate Mapping,我有一个包含5列的Person对象,我使用了以下属性: property name="firstName" column="FirstName" type="string" lazy="false" property name="lastName" column="LastName" type="string" lazy="true" property name="city" column="City" type="string" lazy="true" property name="c
property name="firstName" column="FirstName" type="string" lazy="false"
property name="lastName" column="LastName" type="string" lazy="true"
property name="city" column="City" type="string" lazy="true"
property name="country" column="Country" type="string" lazy="true"
property name="phone" column="Phone" type="string" lazy="true"
现在,我如何确定使用“From Person”返回的对象是否只包含名为的数据行——假设其他4行是延迟加载的。我尝试了调试器,但当我深入时,我看到所有的值都已经存在了。。。有什么东西不见了吗?谢谢这可能会有帮助:
但是,如果这是一个目标,我认为它不会显著提高性能,除非表中有数百列。Leazy加载在创建集合时会产生很大的不同。您可以使用配置
hibernate.show\u sql=true
并查看输出sql。要了解它是否是延迟加载的,而无需检查生成的sql,只需关闭会话,然后访问属性即可
但是,您需要进一步的字节码增强来启用这种行为
例如,在增强字节码以允许在Note和running中延迟加载horse(字符串属性)之后
Criteria criteria = session.createCriteria(Note.class);
List<Note> list1 = criteria.list();
session.close();
String horse = list1.get(0).getHorse();
Caused by: org.hibernate.LazyInitializationException: Unable to perform requested lazy initialization [stackoverflow.Note.horse] - no session and settings disallow loading outside the Session
at org.hibernate.bytecode.enhance.spi.interceptor.Helper.throwLazyInitializationException(Helper.java:165)