These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Restrict fields in SELECT statement
PostPosted: Wed Apr 15, 2009 1:27 am 
Newbie

Joined: Mon Feb 23, 2009 9:08 am
Posts: 9
Hi newbie to hibernate and just wanted to get your thoughts on the following:

I have a POJO called Client that contains all information about a client ie.: firstname, surname, dob... etc.

I implemented a search functionality that searches for clients by Surname but when I view the sql generated by hibernate i noticed that hibernate fetches all fields defined in the Client POJO. ie.: SELECT FirstName, Surname, DOB, Occupation, Income FROM Client

However for performance i would prefer to restrict the output to SELECT FirstName, Surname FROM Client.

What would be the best way to achieve this in hibernate, i mean theres no point returning/fetching all attributes from the Client table when im only using the firstname and surname to display the found clients.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 15, 2009 2:12 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
There are multiple solution for this problem -

Either use customised query like

Code:
select firstName, lastName from Client where lastName like :lastName


Another way is lazy loading of properties - which can lead you to n+1 problem if you don't use that properly.

http://www.hibernate.org/hib_docs/v3/re ... properties


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.