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