Play Framework, PostGIS and Hibernate Spatial

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Play Framework, PostGIS and Hibernate Spatial

Oliver Schrenk
Hi,

I'm trying to write play-framework driven GIS application with the following configuration:

        db.driver=org.postgresql.Driver
        db.url=jdbc:postgresql://localhost:5432/gis
        jpa.dialect=org.hibernatespatial.postgis.PostgisDialect

I use the following code to call a native query:

        Query query=JPA
                                        .em()
                                        .createNativeQuery(
                                                "SELECT transform(way, 4326) as way2 ,Distance(transform(GeometryFromText('POINT(6.77 51.222)', 4326 ), 900913), way) as distance from planet_osm_point where amenity='fuel' order by distance;");
                        //SQLQuery addScalar=query.unwrap(SQLQuery.class).addScalar("way2", GeometryUserType.TYPE);
                        query.getResultList();

and I get the following error:

        org.hibernate.MappingException: No Dialect mapping for JDBC type: 1111

With the addScalar method I get:

        Can't convert object of type org.postgresql.util.PGobject
       

Now If I switch to the DriverWrapper class provided by postgis-2.0.0.jar using

        db.driver=org.postgis.DriverWrapper
        db.url=jdbc:postgresql_postGIS://localhost:5432/gis
        jpa.dialect=org.hibernatespatial.postgis.PostgisDialect

I get

        [...]
        at org.postgresql.Driver.connect(Driver.java:260)
                at org.postgis.DriverWrapper.connect(Unknown Source)
                at java.sql.DriverManager.getConnection(DriverManager.java:582)
        [...]
        Caused by: java.lang.ClassNotFoundException: org.postgis.PGbox3d
                at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
                at java.security.AccessController.doPrivileged(Native Method)
                at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
                at sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
                at java.lang.Class.forName0(Native Method)
                at java.lang.Class.forName(Class.java:169)

Which I don't understand because postgis-2.0.0.jar is clearly in the classpath even the DriverWrapper being in the same package is used further up in the stack trace.


Any ideas?

       
Best regards
Oliver Schrenk

I'm using

OSX 10.6.8
Postgresql postgresql 9.0.4
Postgis 1.5.3
Play Framework 1.2.3 (master-b15323b)

I have the following libs in my classpath:

hibernate-spatial-1.1.jar
hibernate-spatial-postgis-1.1.jar
jts-1.11.jar
postgis-2.0.0.jar (compiled from SVN with postgresql-9.0-801.jdbc4.jar in CLASSPATH)
postgresql-9.0-801.jdbc4.jar
 
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: Play Framework, PostGIS and Hibernate Spatial

Oliver Schrenk
I found the problem when I tried to recompile the postgresql jdbc
driver itself to do some debugging.
I don't know when or why but I already had a postgresql jdbc in my
classpath. The culprit was found in

/Library/Java/Extensions/postgresql-8.2-506.jdbc3.jar

May be some old installer has deployed it there I don't know. Once
removed the driver in the lib directory was able to pickup the correct
har and class. I think the postgresql-8.2-506.jdbc3.jar was prior to
the other one in the classpath and was called by the driver wrapper.
This jar then used its own classloader in its directory and wasn't
able to find the correct class.


> I'm trying to write play-framework driven GIS application with the following configuration:
>
> db.driver=org.postgresql.Driver
> db.url=jdbc:
> postgresql://localhost:5432/gis
>
> jpa.dialect=org.hibernatespatial.postgis.PostgisDialect
>
> I use the following code to call a native query:
>
> Query query=JPA
> .em()
> .createNativeQuery(
> "SELECT transform(way, 4326) as way2 ,Distance(transform(GeometryFromText('POINT(6.77 51.222)', 4326 ), 900913), way) as distance from planet_osm_point where amenity='fuel' order by distance;");
> //SQLQuery addScalar=query.unwrap(SQLQuery.class).addScalar("way2", GeometryUserType.TYPE);
> query.getResultList();
>
> and I get the following error:
>
> org.hibernate.MappingException: No Dialect mapping for JDBC type: 1111
>
> With the addScalar method I get:
>
> Can't convert object of type org.postgresql.util.PGobject
>
>
> Now If I switch to the DriverWrapper class provided by postgis-2.0.0.jar using
>
> db.driver=org.postgis.DriverWrapper
> db.url=jdbc:
> postgresql_postGIS://localhost:5432/gis
>
> jpa.dialect=org.hibernatespatial.postgis.PostgisDialect
>
> I get
>
> [...]
> at org.postgresql.Driver.connect(Driver.java:260)
> at org.postgis.DriverWrapper.connect(Unknown Source)
> at java.sql.DriverManager.getConnection(DriverManager.java:582)
> [...]
> Caused by: java.lang.ClassNotFoundException: org.postgis.PGbox3d
> at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
> at sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
> at java.lang.Class.forName0(Native Method)
> at java.lang.Class.forName(Class.java:169)
>
> Which I don't understand because postgis-2.0.0.jar is clearly in the classpath even the DriverWrapper being in the same package is used further up in the stack trace.
>
>
> Any ideas?
>
>
> Best regards
> Oliver Schrenk
>
> I'm using
>
> OSX 10.6.8
> Postgresql postgresql 9.0.4
> Postgis 1.5.3
> Play Framework 1.2.3 (master-b15323b)
>
> I have the following libs in my classpath:
>
> hibernate-spatial-1.1.jar
> hibernate-spatial-postgis-1.1.jar
> jts-1.11.jar
> postgis-2.0.0.jar (compiled from SVN with postgresql-9.0-801.jdbc4.jar in CLASSPATH)
> postgresql-9.0-801.jdbc4.jar
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users