aspose file tools*
The moose likes Object Relational Mapping and the fly likes hibernate query problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate query problem" Watch "hibernate query problem" New topic
Author

hibernate query problem

Venkata Kumar
Ranch Hand

Joined: Apr 16, 2008
Posts: 110

Hello All,

I have an domain object Student with some attributes Id, first_name,last_name,contact_number etc. I want to get only first_name and last_name for all the students and return value should be list of student objects.


The following sql is returning list of student objects.




Where as the following sql is returning list of arrays. I want to get the result as List of student objects



If anyone knows how to get list of domain objects populated with first_name and last_name please let me know


SCJP 5.0, SCWCD 5, preparing for SCDJWS
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

Well, Hibernate will simply return fully populated instances. As you see, custom queries return arrays of data. You're basically demonstrating the two alternative here. I'm not sure if a third option exists.

You could create a new class that only has the first and last names and then map it to the db, and query based on this new object, but I think that's the best you're going to do.

-Cameron McKenzie
Venkata Kumar
Ranch Hand

Joined: Apr 16, 2008
Posts: 110

Thanks Cameron.

-Venkat
Benjamin Winterberg
Ranch Hand

Joined: Sep 19, 2007
Posts: 36
You can do something like this if appropriate constructor in class student exists:



Hibernate DAOs with Spring | Separation of Concerns | Eclipse Code Templates | more...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hibernate query problem
 
Similar Threads
Query question
Pesudo coding
Basic Hibernate many-to-many mapping / query not right
How to check special characters in java code using Java.util.regex package
Hibernate with native SQL issue