Nick
Nick

Reputation: 43

Using Spring Hibernate to get an object or specific columns

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

Answers (2)

Robby Pond
Robby Pond

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

Raman
Raman

Reputation: 1517

In Hibernate too, 1st practice is better to reduce the load.

Upvotes: 0

Related Questions