Hello!
I use PostgreSQL with PostGIS and Eclipselink. In the Postgres database I have some stored functions, as I know with Postgres stored functions + Eclipselink doesn't work the @NamedStoredProcedureQuery annotation, StoredProcedureCall and StoredFunctionCall methods, therefore i use @NamedNativeQuery.
I wrote a GeometryConverter, that works fine when I persist
my entity, and with
@NamedNativeQuery(name = "getEntity", query = "SELECT * FROM GET_ENTITY(?)", resultClass = Entity.class)
Here is my GeometryConverter:
public Geometry convertDataValueToObjectValue(Object dataValue, Session session) {
if (dataValue == null) {
return null;
} else if (dataValue instanceof PGgeometry) {
return ((PGgeometry) dataValue).getGeometry();
} else {
log.severe("dataValue not instance of PGgeometry");
return null;
}
}
@Override
public PGgeometry convertObjectValueToDataValue(Object objectValue, Session session) {
if (objectValue == null) {
return null;
// } else if (objectValue instanceof Geometry) {
// return new PGgeometry((Geometry)objectValue);
} else if (objectValue instanceof Point) {
return new PGgeometry((Point)objectValue);
} else if (objectValue instanceof MultiPoint) {
return new PGgeometry((MultiPoint)objectValue);
} else if (objectValue instanceof LineString) {
return new PGgeometry((LineString)objectValue);
} else if (objectValue instanceof MultiLineString) {
return new PGgeometry((MultiLineString)objectValue);
} else if (objectValue instanceof Polygon) {
return new PGgeometry((Polygon)objectValue);
} else if (objectValue instanceof MultiPolygon) {
return new PGgeometry((MultiPolygon)objectValue);
} else if (objectValue instanceof GeometryCollection) {
return new PGgeometry((GeometryCollection)objectValue);
} else {
log.severe("objectValue not instance of Geometry");
return new PGgeometry();
}
}
@Override
public void initialize(DatabaseMapping dm, Session session) {
dm.getField().setSqlType(java.sql.Types.OTHER);
}
But when I want to use this stored function
@NamedNativeQuery(name = "getEntityGeom", query = "SELECT * FROM GET_ENTITY_GEOM(?)")
the ? parameter is a Postgis/Postgresql geometry type, throw the following exception:
Internal Exception: org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of org.postgis.MultiLineString. Use setObject() with an explicit Types value to specify the type to use.
I can see that the converter doesn't convert the org.postgis.MultiLineString to org.postgis.PGgeometry. What should I set to work my converter?
Thanks for your help!
Tamas J
[Updated on: Tue, 08 February 2011 12:11]
Report message to a moderator