-->
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.  [ 3 posts ] 
Author Message
 Post subject: Help: Projections.max
PostPosted: Mon Mar 20, 2006 1:16 pm 
Newbie

Joined: Fri Nov 14, 2003 8:37 am
Posts: 14
Location: Hamburg - Germany
Hi Folks,

when I try to iterate over the resulting list of:

Criteria crt = session.createCriteria(Topic.class);

crt.setProjection(Projections.projectionList().
add(Projections.max("topicTime")).
add(Projections.groupProperty("topicId"))
);

return crt.list();

I don´t get a list of Topics. Instead I get a list of: "CLASS_NAME = [Ljava.lang.Object;"

What´s wrong? How do I tell the criteria to return a List of Topics?

Thanks & Regards,

Chris

Hibernate version: 3.1.2


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 20, 2006 1:39 pm 
Newbie

Joined: Mon Mar 20, 2006 1:16 pm
Posts: 5
My understanding is that you would use a Transformer. There is an example here http://blog.hibernate.org/cgi-bin/blosx ... d_sql.html.

I have used AliasToBeanResultTransformer successfully. Your code would look something like this

Code:
crt.setProjection(Projections.projectionList().
add(Projections.max("topicTime"), "topicTime").
add(Projections.groupProperty("topicId"), "topicId").
setResultTransformer( new AliasToBeanResultTransformer(Topic.class))
);

return crt.list();


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 21, 2006 5:03 am 
Newbie

Joined: Fri Nov 14, 2003 8:37 am
Posts: 14
Location: Hamburg - Germany
That did the trick! Thanks!

davilch wrote:
My understanding is that you would use a Transformer. There is an example here http://blog.hibernate.org/cgi-bin/blosx ... d_sql.html.

I have used AliasToBeanResultTransformer successfully. Your code would look something like this

Code:
crt.setProjection(Projections.projectionList().
add(Projections.max("topicTime"), "topicTime").
add(Projections.groupProperty("topicId"), "topicId").
setResultTransformer( new AliasToBeanResultTransformer(Topic.class))
);

return crt.list();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.