File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark ""New to Hibernate" Question - How to fetch only a few fields" Watch ""New to Hibernate" Question - How to fetch only a few fields" New topic
Author

"New to Hibernate" Question - How to fetch only a few fields

Andrei Antonescu
Ranch Hand

Joined: Jul 08, 2010
Posts: 75
Hello,

I am having an object like "Person" (id, name, birthday etc). I want to put all the persons names into a select. For that I only need the name and an ID. How can I fetch only those 2 fields (using HQL)? I have tried like this:



where PersonSelect is just a POJO with a name and an id. It does not work. It says that the constructor can't be found(I have build the constructor in the regular way ...PersonSelect(String name,Long id).... ).

Please help.

Thanks.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 63052
    
  69

POJOs need a no-arg constructor.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Andrei Antonescu
Ranch Hand

Joined: Jul 08, 2010
Posts: 75
That worked. Thank you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "New to Hibernate" Question - How to fetch only a few fields
 
It's not a secret anymore!