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

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


Hi Fred,

    In the function "dao.alterar(to, null, null);" it opens a new session to
save. But, following your sugestion, I moved  the "commit" line down and is
happening the same problem.

[]'s

PA

On Thu, Aug 26, 2010 at 3:19 PM, Fred Lehodey <lehodey at gmail.com> wrote:

> Hi,
>
> May be doing the commit after the setPoli... ?! :
>
> to.setPoli(geom);
> dao.commitTransaction(session, tx);
>
> Fred
>
>
>
> On Thu, Aug 26, 2010 at 7:11 PM, Paulo Angelo <pa at pauloangelo.com> wrote:
>
>> 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
>>
>> _______________________________________________
>> postgis-users mailing list
>> postgis-users at postgis.refractions.net
>> http://postgis.refractions.net/mailman/listinfo/postgis-users
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20100826/30080b1b/attachment.html>


More information about the postgis-users mailing list