2011-05-27 70 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 
相關問題