Can save but not retrieve using Hibernate+PostGIS+JTS

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Can save but not retrieve using Hibernate+PostGIS+JTS

Paulo Angelo
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 ="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);
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);
// 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>

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

import com.vividsolutions.jts.geom.Geometry;
private Geometry poli;

What is wrong?

Thank you for help.


Paulo Angelo
hibernatespatial-users mailing list
[hidden email]