开发者

Mapping A Field To A Custom Query in OpenJPA

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 开发者_Go百科(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


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.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜