Hiberante one-to-one lazy loading

http://www.ucai8.com/viewNote.do?noteId=402881851e7c2cd2011e7c65e32e002d

这几天在调试hibernate性能,在后台发现执行一个查询时生成了多条SQL语句。仔细研究后,发现是因为User对象有4个one-to-one关系。Hibernate查询时会先查询User对象,然后再对每一个User对象查询4个一对一关系的对象。这样如果我要查10个User对象时,会产生41条SQL语句。而有时我只会用到User对象的内容,不会用到其它4个关联的对象,我想对这4个对象进行延时加载。在网上查了资料后,发现Hibernate对我说的这种情况还是不支持。以下是原文。

The bottom line is that (N)Hibernate does not support lazy loading of one-to-one relations. There are several posts and explanations on why. There is one post out there by yours truly that says that it's possible and how, but you should ignore it as is was purely the result of a brain-fart in someone who was a novice a the time. 

Essentially, if you want to have lazy loading don't use one-to-one, use one-to-many. 

参考:http://forum.hibernate.org/viewtopic.php?t=975957

友财网作者 http://www.ucai8.com

你可能感兴趣的:(sql,Hibernate,PHP)