Querying my JPA provider (Hibernate) for a collection of <Id,Name> of an entity

Posted by Ittai on Stack Overflow See other posts from Stack Overflow or by Ittai
Published on 2011-02-20T15:25:24Z Indexed on 2011/02/20 23:24 UTC
Read the original article Hit count: 180

Filed under:
|
|
|

Hi,
I have an entity which looks something like this:
Id (PK) Name
Other business properties and associations...

I have the need for my DAL (JPA with hibernate as provider) to return a list of the entities which correlate to some constraints (or just return them all) but instead of returning the entities themselves I'd like to receive only the Id and the Name properties.
I know this can be achieved with HQL/SQL (something like: select id,name from entity where...) but I don't want to go down that road.
I was thinking of somehow defining the pair a compositioned part of the entity and thought that might help me but I'm not sure that's "legal" as the Id is the PK.
The logic for this scenario is to have a textbox which asynchronously queries the web-service (and through it the DAL) for the relevant entities and once an entity is selected then it is loaded as a whole and shipped to the front-end.

Would appreciate any feedback,
Ittai

© Stack Overflow or respective owner

Related posts about java

Related posts about hibernate