将字段映射到 OpenJPA 中的自定义查询
我有一堂课,位置。位置包含定义其边界的坐标列表。
@Entity
@Table(name="LOCATION")
public class Location implements Serializable {
private int id;
private List<Coordinates> coordinateList;
// setters and getters w/ mapping annotations
}
坐标列表与保存坐标的表映射@OneToMany。
我想要做的是将四个字段(或地图)添加到位置类中:
- maxLat(最大纬度)
- minLat(最小纬度)
- maxLng (等)
- minLng
是否可以使用自定义查询来注释这些字段以填充它们?即
@CustomQueryOrSomething("select max(lat) from Coordinates C where C.location.id = " this.id)
public getMaxLat() {}
杰森
I have a class, Location. Location contains a List of coordinates that define its border.
@Entity
@Table(name="LOCATION")
public class Location implements Serializable {
private int id;
private List<Coordinates> coordinateList;
// setters and getters w/ mapping annotations
}
The coordinateList is mapped @OneToMany with the table that holds the coordinates.
What I would like to do is add four fields (or a Map) to the Location class:
- maxLat (maximum Latitude)
- minLat (minimum Latitude)
- maxLng (etc)
- minLng
Is it possible to annotate this fields with a custom query to populate them? i.e.
@CustomQueryOrSomething("select max(lat) from Coordinates C where C.location.id = " this.id)
public getMaxLat() {}
Jason
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要回答您的问题,不,我认为没有办法用特定查询填充实体单个字段。您可以使用选择为给定位置创建特殊的范围类/实体/可嵌入。
To answer your question, no I don't think there is a way to populate an Entity single field with a specific query. You could use a select to create a special Range class/Entity/Embeddable for a given location.