2011-05-27 41 views
0

我有一个类,位置。位置包含定义其边框的坐标列表。将字段映射到OpenJPA中的自定义查询

@Entity 
@Table(name="LOCATION") 
public class Location implements Serializable { 

    private int id; 
    private List<Coordinates> coordinateList; 

    // setters and getters w/ mapping annotations 

} 

coordinateList被映射@OneToMany与保存坐标的表。

我想什么做的就是添加四个字段(或地图)的位置类:

  • maxLat(最大纬度)
  • minLat(最低纬度)
  • maxLng(等)
  • minLng

是否有可能注释自定义查询这个领域来填充呢?即

@CustomQueryOrSomething("select max(lat) from Coordinates C where C.location.id = " this.id) 
public getMaxLat() {} 

杰森

回答

2

要回答你的问题,不,我不认为有一种方法来填充实体单场与特定查询。您可以使用select为给定位置创建特殊的Range类/ Entity/Embeddable。

SELECT NEW com.bla.Range(max(lat), min(lat), max(long), min(long)) Coordinates C where C.location.id = :loc_id 
相关问题