使用 Spring Hibernate 获取对象或特定列
我有一个简单的问题:获取整个列(对象)比获取单个列(对象)更昂贵吗?
哪一种是更好的做法?
getHibernateTemplate().find("select uid, username,email from User ");
or using
getHibernateTemplate().find("from User ");
并从检索到的对象中获取各个列?在 SQL 中,第一个是更好的实践,那么 Hibernate 怎么样?
I have a simple question: is it more expensive to get the whole columns(the object) than getting the individuals ones?
Which one is a better practice?
getHibernateTemplate().find("select uid, username,email from User ");
or using
getHibernateTemplate().find("from User ");
and getting the individual columns from the retrieved object? In SQL the first one is a better practice how about Hibernate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这实际上取决于您的对象映射是什么。如果拉动行时不需要联接,那么我认为拉动整行与单个列之间的差异可以忽略不计。
另一方面,如果您的对象与其他对象有多个其他关系,那么执行投影而不是整个列检索可能会产生很大的性能差异。
It really depends on what your object mappings are. If there are no joins required in pulling a row then I think the difference between pulling the entire row vs individual columns would be negligible.
On the other hand if your Object has several other relationships to other objects, then there could be a big performance difference in performing a Projection instead of an entire column retrieval.
在 Hibernate 中也是如此,第一种做法可以更好地减少负载。
In Hibernate too, 1st practice is better to reduce the load.