Jason
Jason

Reputation: 4130

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:

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

Upvotes: 0

Views: 158

Answers (1)

Rick
Rick

Reputation: 3840

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

Upvotes: 2

Related Questions