-->
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.  [ 1 post ] 
Author Message
 Post subject: Mapping calculated field from sql-query to transient attribu
PostPosted: Mon Feb 08, 2010 11:28 am 
Newbie

Joined: Mon Feb 08, 2010 11:20 am
Posts: 1
Hi there,

in my application I perform a SQLQuery which should return all fields of an object PLUS a field calculated via the query.
As I only want to return objects of the expected Class, I want to map the calculated field to a transient object attribute.

The object has some attributes plus this one:
Code:
@Transient
   private Double distance;


The query looks like this:

Code:
String sql = "select *, ( 6371 * acos( cos( radians(latitude) ) * cos( radians( :lat ) ) * cos( radians( :long ) - radians(longitude) ) + sin( radians(latitude) ) * sin( radians( :lat ) ) ) ) as distance"
         + " from Restaurant res where res.status = 1 and "
         + "( 6371 * acos( cos( radians(latitude) ) * cos( radians( :lat ) ) * cos( radians( :long ) - radians(longitude) ) + sin( radians(latitude) ) * sin( radians( :lat ) ) ) ) "
         +  "<= :maxKilometerDistance order by distance";
      
      SQLQuery query = getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery(sql);
      query.setDouble("lat", latitude);
      query.setDouble("long", longitude);
      query.setInteger("maxKilometerDistance", maxKilometerDistance);
      query.addEntity("restaurant", Restaurant.class);
return query.list();


This query does return the object properly, but the attribute
Code:
distance
is null.

Does anyone have any idea if what I want to do is possible?

Eric


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.