在OpenJPA中将字段映射到自定义查询

| 我有一堂课,地点。位置包含定义其边界的坐标列表。
@Entity
@Table(name=\"LOCATION\")
public class Location implements Serializable {

   private int id;
   private List<Coordinates> coordinateList;

   // setters and getters w/ mapping annotations

}
ordinateList与保存坐标的表映射为@OneToMany。 我想做的是在Location类中添加四个字段(或Map): maxLat(最大纬度) minLat(最小纬度) maxLng(等) 分钟 是否可以使用自定义查询注释此字段以填充它们?即
@CustomQueryOrSomething(\"select max(lat) from Coordinates C where C.location.id = \" this.id)
public getMaxLat() {}
杰森     
已邀请:
        要回答您的问题,不,我不认为有一种方法可以用特定查询填充实体单个字段。您可以使用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
    

要回复问题请先登录注册