Reputation: 43
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?
Upvotes: 0
Views: 993
Reputation: 73484
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.
Upvotes: 1