Postgis, Hibernate Spatial

2,573 views
Skip to first unread message

oschrenk

unread,
Sep 8, 2011, 12:23:05 PM9/8/11
to play-framework
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

Keith Swallow

unread,
Sep 8, 2011, 2:16:08 PM9/8/11
to play-fr...@googlegroups.com
Hey Oliver,

Have you tried building from the 1.5.3 jdbc source? It looks like your JDBC is a different version from the PostGis version.


Cheers,

Keith

oschrenk

unread,
Sep 12, 2011, 8:07:40 AM9/12/11
to play-framework
It's the same with using 1.5.3

oschrenk

unread,
Sep 12, 2011, 12:18:57 PM9/12/11
to play-framework
And the same with postgresql-9.1-901.jdbc4.jar

oschrenk

unread,
Sep 12, 2011, 5:09:23 PM9/12/11
to play-framework
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.

Hopefully someone will find this helpful.

Jürgen Zornig

unread,
Feb 24, 2013, 12:04:28 PM2/24/13
to play-fr...@googlegroups.com
Hi Oliver,

Did you get hibernate4 and hibernate spatial 4 up and running with play framework already,or does it only work with versionnumbers you posted here?

Im just new to play and first of all I wanted to try out, if I can use the framework for prototyping spatial applications. Unfortunately I had no luck with hibernate4 until now.

best regards,

Jürgen

Brian Holtz

unread,
Jul 5, 2013, 2:28:28 PM7/5/13
to play-fr...@googlegroups.com
Hi Jurgen, you commented at StackOverflow that you got the computer-database-jpa sample to work with hibernate spatial.  Can you share your example?

Brian Holtz

unread,
Aug 5, 2013, 12:00:53 AM8/5/13
to play-fr...@googlegroups.com
I got this working awhile back. Anybody can email brian at holtz.org if they have issues bringing up Play with Hibernate Spatial.

Tran Viet Hung

unread,
Oct 13, 2013, 11:52:49 AM10/13/13
to play-fr...@googlegroups.com, brianho...@gmail.com
Hi Brian Holtz

I am starting with hibernate spatial with postgressql. I use hibernate-spatial-4.0-M1.jar and postgresql-9.2-1003.jdbc4 to connect.
Can you sent me example?Thanks you!


Vào 01:28:28 UTC+7 Thứ bảy, ngày 06 tháng bảy năm 2013, Brian Holtz đã viết:

Sabrina Breda

unread,
May 16, 2014, 6:12:57 PM5/16/14
to play-fr...@googlegroups.com, brianho...@gmail.com
Hi all,

I would like use Hibernat Spatial with PostgreSQL and PostGIS.
Unfortunately, I found a only one example (at this link http://www.hibernatespatial.org/documentation/02-Tutorial/01-tutorial4/) which uses Maven as tool.
Does anyone know if there is the possibility to use Hibernat Spatial with PostGIS without the use of Maven?

Thank you all,
Sabrina

Ashitosh Wandre

unread,
Feb 6, 2017, 4:39:38 AM2/6/17
to Play Framework

Dominik Dorn

unread,
Feb 6, 2017, 5:49:40 AM2/6/17
to play-framework
From what it looks like, you just need to provide the dependencies in SBT format instead and also add the repositories to your build.sbt... 

for the dependencies, it goes like this

libraryDependencies += groupID % artifactID % revision
so like
libraryDependencies += "org.hibernate" % "hibernate-spatial" % "4.0"
and for the repositories its like this
resolvers += "OSGEO GeoTools repo" at "http://download.osgeo.org/webdav/geotools"
See http://www.scala-sbt.org/0.13/docs/Library-Dependencies.html for details.

cheers,
dominik

--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/dcd87088-d213-493c-b009-8cf1312bf401%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages