-->
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: Projections and object creation
PostPosted: Wed Mar 23, 2005 1:15 pm 
Newbie

Joined: Wed Mar 23, 2005 1:02 pm
Posts: 4
I'm using Hibernate 3.0rc1 and the projections capability, but in the documentation I have not found any way to have it return a List of partially-filled objects instead of a List of Integers or whatever other data type specifically requested with projections. For example, this code:

Code:
List results = session.createCriteria(Cat.class)
    .setProjection( Property.forName("name") )
    .list();


would return a List of Strings, whereas what I need is a List of my Cat objects that only have their name set on them. This makes more sense when more than one property is desired, such as when 8 out of 10 properties are desired. If no such capability exists in Hibernate, does anyone know why? For my usage, it would be much more consistent and usable if I were able to get Cats back for every request regardless of how many properties were requested.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 23, 2005 1:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Code:
List results = session.createCriteria(Cat.class)
    .setProjection( Property.forName("name") )
    .setResultTransformer( new AliasToBeanResultTransformer(Cat.class) )
    .list();

_________________
Max
Don't forget to rate


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.