Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » PostgreSQL/PostGIS stored function + Eclipselink converter problem
PostgreSQL/PostGIS stored function + Eclipselink converter problem [message #653082] Tue, 08 February 2011 07:09 Go to next message
Tamas J is currently offline Tamas J
Messages: 4
Registered: January 2011
Junior Member
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
em.persist(e);

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 07:11]

Report message to a moderator

Re: PostgreSQL/PostGIS stored function + Eclipselink converter problem [message #653132 is a reply to message #653082] Tue, 08 February 2011 10:38 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

See,

http://stackoverflow.com/questions/4932904/postgresql-postgi s-stored-function-eclipselink-converter-problem


James : Wiki : Book : Blog : Twitter
Previous Topic:How to call Oracle function from eclipselink
Next Topic:deadlock on select
Goto Forum:
  


Current Time: Fri Jul 25 14:29:28 EDT 2014

Powered by FUDForum. Page generated in 0.01573 seconds