[postgis-users] Can save but not retrieve using Hibernate+PostGIS+JTS
Maria Arias de Reyna
marias at emergya.es
Thu Aug 26 23:46:47 PDT 2010
El Thursday 26 August 2010, Paulo Angelo escribió:
> 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
And have you checked that it appears in the database after the commit? Maybe
the commit is not really commited (can't see why, though).
> // 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
>
Have you tried debugging step by step checking that all variables are ok? Are
you sure that "to" is not null instead of to.getPoli()?
Have you tried using Criteria instead of hql? Maybe it is a conversion problem
between geometry types.
Could it be that closing/commiting the transaction is the problem? If
hibernate didn't get all the data on one shot, closing the transaction makes
hibernate unable to get more info from the database.
Anyway, if you rollback a read-only transaction instead committing, hibernate
goes faster.
--
María Arias de Reyna Domínguez
Área de Operaciones
Emergya Consultoría
Tfno: +34 954 51 75 77 / +34 607 43 74 27
Fax: +34 954 51 64 73
www.emergya.es
More information about the postgis-users
mailing list