Hibernate Spatial version 4.3 in Spring with a Tomcat datasource

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

Hibernate Spatial version 4.3 in Spring with a Tomcat datasource

Rolf Wiegand Storgaard
Hi,

I am trying to make a setup with Hibernate, Hibernate Spatial, Spring, PostGIS and Tomcat. I have an application up and running and if I configure the datasource in Spring the application works perfect. But... if I configure the datasource in Tomcat as a resource I can’t get it to work. When using the Tomcat datasource I get the Exception:

org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of org.postgis.PGgeometry. Use setObject() with an explicit Types value to specify the type to use.

As you can see below I have specified the type and as mentioned above it works when I specify the datasource direct in spring.

My setup is:

An entity containing:
@Column(name = "GEOM")
@Type(type = "org.hibernate.spatial.GeometryType")
private Geometry geometry;  

Spring configuration:
<jee:jndi-lookup id="myDataSource" jndi-name=“MY_DS" default-ref="myDataSourceDefinedInSpring" />
<prop key="hibernate.dialect">org.hibernate.spatial.dialect.postgis.PostgisDialect</prop>

Tomcat conf ???: context.xml:
<Resource auth="Container"
          maxActive="120" 
          maxIdle="10" 
          name=“MY_DS"
          username=“username" 
          password=“password"
          poolPreparedStatements="true" 
          type="javax.sql.DataSource" 
          driverClassName="org.postgis.DriverWrapper"
          validatingQuery="select 1"
          url="jdbc:postgresql_postGIS://localhost:5432/mydb"/> 
...

Tomcat lib ??? (added JARs):
- hibernate-spatial-4.3.jar
- jts-1.13.jar
- postgis-jdbc-1.5.2.jar
- postgresql-9.3-1102-jdbc41.jar

Hope someone have a good and easy solusion for Hibernate Spatial version 4.3.

_____________________________________
Med venlig hilsen / Kind Regards

Rolf Wiegand Storgaard | NorthTech
Nørregade 28D, 4. Th. | 1165 København K  


_______________________________________________
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: Hibernate Spatial version 4.3 in Spring with a Tomcat datasource

Karel Maesen
Administrator
Hi Rolf,

The problem lies with how classloaders work in application servers. For the postgresql driver to correctly load the spatial types, it needs to be in the same classlaoder as the postgis.jar. See this discussion: https://gist.github.com/bjornharrtell/3054462

Regards,

Karel



> On 02 Feb 2015, at 15:55, Rolf Wiegand Storgaard <[hidden email]> wrote:
>
> Hi,
>
> I am trying to make a setup with Hibernate, Hibernate Spatial, Spring, PostGIS and Tomcat. I have an application up and running and if I configure the datasource in Spring the application works perfect. But... if I configure the datasource in Tomcat as a resource I can’t get it to work. When using the Tomcat datasource I get the Exception:
>
> org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of org.postgis.PGgeometry. Use setObject() with an explicit Types value to specify the type to use.
>
> As you can see below I have specified the type and as mentioned above it works when I specify the datasource direct in spring.
>
> My setup is:
>
> An entity containing:
> @Column(name = "GEOM")
> @Type(type = "org.hibernate.spatial.GeometryType")
> private Geometry geometry;  
>
> Spring configuration:
> …
> <jee:jndi-lookup id="myDataSource" jndi-name=“MY_DS" default-ref="myDataSourceDefinedInSpring" />
> …
> <prop key="hibernate.dialect">org.hibernate.spatial.dialect.postgis.PostgisDialect</prop>
>
> Tomcat conf ???: context.xml:
> …
> <Resource auth="Container"
>           maxActive="120"
>           maxIdle="10"
>           name=“MY_DS"
>           username=“username"
>           password=“password"
>           poolPreparedStatements="true"
>           type="javax.sql.DataSource"
>           driverClassName="org.postgis.DriverWrapper"
>           validatingQuery="select 1"
>           url="jdbc:postgresql_postGIS://localhost:5432/mydb"/>
> ...
>
> Tomcat lib ??? (added JARs):
> - hibernate-spatial-4.3.jar
> - jts-1.13.jar
> - postgis-jdbc-1.5.2.jar
> - postgresql-9.3-1102-jdbc41.jar
>
> Hope someone have a good and easy solusion for Hibernate Spatial version 4.3.
>
> _____________________________________
> Med venlig hilsen / Kind Regards
>
> Rolf Wiegand Storgaard | NorthTech
> Nørregade 28D, 4. Th. | 1165 København K  
> +45 26 18 86 26 | [hidden email] | http://www.northtech.dk/
>
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users