[postgis-users] Can save but not retrieve using Hibernate+PostGIS+JTS

Paulo Angelo pa at pauloangelo.com
Thu Aug 26 11:11:12 PDT 2010


Hi Ppl,

  I'm getting a weird problem. I can save a Geometry type through Hibernate
but I can't retrieve it.

 WKTReader fromText = new WKTReader();
 Geometry geom = fromText.read("POLYGON((0 0,0 3,3 3,3 0,0 0))");
Session session = dao.newSession();
Transaction tx =  dao.beginTransaction(session);
Query q = session.createQuery("select f from Geometries f");
List list = q.list();
Poligono to = (Poligono) lista.get(0);
dao.commitTransaction(session, tx);
to.setPoli(geom);
System.out.println(to.getPoli().toString());  // Apears "POLYGON ((0 0, 0 3,
3 3, 3 0, 0 0))"
dao.alterar(to, null, null);
 // I can see via SQL that it saves correctly

// Now, retrieve
session = dao.newSession();
tx =  dao.beginTransaction(session);
q = session.createQuery("select f from Geometries f");
list = q.list();
to = (Poligono) lista.get(0);
dao.commitTransaction(session, tx);
System.out.println(to.getPoli().toString());
 // Get a *NullPointerException*, because to.getPoli() is null



The hibernate.cfg.xml
...
    <property
name="hibernate.dialect">org.hibernatespatial.postgis.PostgisDialect</property>
    <property name="hibernate.show_sql">true</property>
       <property
name="hibernate.cglib.use_reflection_optimizer">true</property>
       <property
name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
       <property
name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
...

The poligono.hbm.xml
...
 <property name="Poli" type="org.hibernatespatial.GeometryUserType">
           <column name="f0209_poli"  sql-type="geometry">
               <comment>Poligono</comment>
           </column>
       </property>
...

The Poligono.java
...
import com.vividsolutions.jts.geom.Geometry;
...
private Geometry poli;
...


What is wrong?

Thank you for help.

Att,

Paulo Angelo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20100826/bbfbca1f/attachment.html>


More information about the postgis-users mailing list