尝试确认延迟加载是否正常 [英] Trying to confirm lazy loading is working

查看:79
本文介绍了尝试确认延迟加载是否正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习休眠,并且正在使用调试器来了解休眠如何获取对象.我在XML中启用了延迟加载,并使用创建查询来获取对象.该对象具有关联的Set.

I am learning hibernate and i am using the debugger to understand how hibernate fetches objects. I have enabled lazy loading in my XML and i use create a query to get an object. This object has a Set associated with it.

当我在调试器中查看变量值时,似乎已完全加载了对象图,即没有懒惰地获取集合及其属性.我可以想到几种可能的原因.

When i look at the variable values in my debugger it seems to be completely loading the object graph, ie not lazily fetching the set and its properties. I can think of several reasons why this might be the case.

1)我的xml/config出了点问题,并且我渴望启用抓取功能.我不确定情况是否如此,所有设置都默认为延迟获取.

1) something is wrong with my xml / config and i have eager fetching enabled. I'm not sure this is the case, everything is at its defaults which is to lazy fetch.

2)IDE调试器的工作方式是,当我查看它们时,它会导致休眠状态触发延迟加载.

2) The way the IDE debugger works is that is causes hibernate to trigger the lazy loading when i look at them.

3)Hibernate正在从第二级缓存中获取整个对象图.香港专业教育学院试图禁用此功能,但这似乎没有效果

3) Hibernate is fetching the entire object graph from the 2nd level cache. Ive tried to disable this but this seems to have no effect

还有其他想法吗?

推荐答案

调试(精确地显示惰性字段)已经触发了惰性加载.获取实体,分离它并访问您的惰性字段.如果延迟加载有效,则应该抛出某种异常.

Debugging (showing the lazy fields, to be precise) triggers the lazy loading already. Get the entity, detach it and access your lazy field. Should throw some sort of exception if lazy loading works.

如果您真的想知道 休眠方式,请查看源代码.

If you really want to know how hibernate does it, have a look at the sources.

这篇关于尝试确认延迟加载是否正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆