-->
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: Assign objects from query result
PostPosted: Fri Sep 11, 2009 6:01 am 
Newbie

Joined: Thu Aug 27, 2009 6:28 am
Posts: 19
Hi,
I am having the student class which having FName,LName,num. Now I need to get FName,LName,num,Total(sum of num).
If i do like below I got the objects in the list
Code:
    var Query = "select std from student std"
      IList< student> list = HibernateTemplate.Find< student>(Query);

But i need to get the total also, so I have added total in the class. then If i do like
Code:
var Query = "select std.FName, std.LName,std.num,sum(std.num) from student std"
      IList< student> list = HibernateTemplate.Find< student>(Query);

Its shows an exception.
How to add the assign the additional properties into student class which should not map with the database column.

Thanks&Regards
Nizam deen

_________________
Thanks & Regards
Nizam Abdul


Top
 Profile  
 
 Post subject: Re: Assign objects from query result
PostPosted: Mon Sep 14, 2009 2:30 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You can use a formula for a property:

http://nhforge.org/doc/nh/en/index.html#mapping-declaration-property

But I'm not sure if that's the solution to your problems, because afaik using sum like you want to requires a group by clause. Maybe you need a SQL query and map the result set accordingly:

http://nhforge.org/doc/nh/en/index.html#querysql-creating

_________________
--Wolfgang


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.