Displaying calculated fields in sleep mode

I'm not sure if this is possible in Hibernate, but it would be great if it was :) I didn't get past the conceptual stage, but I'll explain as best I can.

I want to use Oracle Spatial functionality for proximity based search. Imagine I have a location object that stores a latitude / longitude value. Then imagine I want to query all locations within 5 km of a user-specified latitude / longitude location. In the results, I want to see all the relevant locations, but besides the standard display fields in the Location object, I also want to represent the distance of each location relative to the user-specified location.

Oracle Spatial has allowed me to do this as a computed field in SQL, but I don't understand how Hibernate can support computed fields that are returned from the database. Since the calculated field is not a column in the table, I cannot do the standard display.

Are there any special functions that allow me to create wrappers for POJOs and have a Hibernate map for them so that additional calculated properties can be returned?

+2


source to share


2 answers


I found using JPA annotations that I can simply create a property on the mapped object with the same name as the sql calculated field (eg "distance") and annotate it like:

@Column(insertable=false, updatable=false)
private Double distance;

      



And that should display the property and not throw an error when you try to save back from the DB.

note that the correct annotation is being updated (not being updated as it was originally posted)

+2


source


Have you looked at Hibernate Spatial and its Oracle10g / 11g Provider ?



Hibernate Spatial is a generic extension to Hibernate for handling geographic data. Hibernate Spatial is open source and licensed such as Hibernate under the LGPL.

Hibernate Spatial allows you to deal with geographic data in a standardized way. It abstracts from a specific way of maintaining a geographic database and a standardized, cross-domain interface for storing geographic data and function requests.

Hibernate Spatial supports most of the functionality of the simple function OGC Specification. Supported databases are: Oracle 10g / 11g, Postgresql / Postgis and MySQL.

+1


source







All Articles