是否有办法使用Hibernate创建一个SQL查询,该查询返回实体的所有属性和一个额外的聚合列,并将结果通过实体映射进行映射,并将聚合列映射到一个瞬态属性同一个实体类?
SQL查询:
@Entity
@Table(name = "xxx")
@Spatial(name = "place")
public class Place extends BasicEntity {
/**
* The id of the place in the third party information service.
*/
@Column(name = "external_id", unique = true)
private String externalId;
/**
* The place's name.
*/
@Column(name = "name")
private String name;
/**
* The place latitude.
*/
@Latitude(of = "place")
private Double latitude;
/**
* The place longitude.
*/
@Longitude(of = "place")
private Double longitude;
... some other attributes.
/**
* The distance between the place and the user's location.
*/
@Transient
private double distance;
... setters and getters
}
实体:
Query query = this.getSessionFactory().getCurrentSession().createSQLQuery(sql).addEntity(Place.class)
Hibernate查询:
grid