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

dave.potts at pinan.co.uk dave.potts at pinan.co.uk
Fri Aug 27 00:26:19 PDT 2010


Hi

Have you checked in the postgres database logs?

There might be a clue in there as to why it is not working

> 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
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>


-- 
Any views expressed in this message are those of the individual sender,
except where the sender specifically states them to be the views of the
Pinan Software





More information about the postgis-users mailing list