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

Paulo Angelo pa at pauloangelo.com
Fri Aug 27 09:53:05 PDT 2010


Hi Ppl..

   Finally I found the problem.  I put some breakpoints at
"AbstractDBGeometryType" and realized that there were a
"postgresql-jdbc3.jar" hidden in a JBoss lib folder, which is in
classpath.

   I just removed the "postgresql-jdbc3.jar" and now is running...

Thank you for help.

Att,

Paulo Angelo


On Fri, Aug 27, 2010 at 3:46 AM, Maria Arias de Reyna <marias at emergya.es> wrote:
> 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
>



More information about the postgis-users mailing list