Hi Ppl,<br><br> I'm getting a weird problem. I can save a Geometry type through Hibernate but I can't retrieve it.<br><br><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;">
WKTReader fromText = new WKTReader();<br> Geometry geom = fromText.read("POLYGON((0 0,0 3,3 3,3 0,0 0))");<br> Session session = dao.newSession();<br> Transaction tx = dao.beginTransaction(session);<br> Query q = session.createQuery("select f from Geometries f");<br>
List list = q.list();<br> Poligono to = (Poligono) lista.get(0);<br> dao.commitTransaction(session, tx);<br>to.setPoli(geom);<br> System.out.println(to.getPoli().toString()); // Apears "POLYGON ((0 0, 0 3, 3 3, 3 0, 0 0))"<div>
dao.alterar(to, null, null);</div><div> // I can see via SQL that it saves correctly</div><div><br></div><div>// Now, retrieve</div><div>session = dao.newSession();</div><div> tx = dao.beginTransaction(session);</div>
<div> q = session.createQuery("select f from Geometries f");</div><div> list = q.list();</div><div> to = (Poligono) lista.get(0);</div><div> dao.commitTransaction(session, tx);</div><div> System.out.println(to.getPoli().toString());</div>
<div> // Get a <b>NullPointerException</b>, because to.getPoli() is null</div></blockquote><div><br><br>The hibernate.cfg.xml<br>...<br> <property name="hibernate.dialect">org.hibernatespatial.postgis.PostgisDialect</property><br>
<property name="hibernate.show_sql">true</property><br> <property name="hibernate.cglib.use_reflection_optimizer">true</property><br> <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property><br>
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property><br>...<br><br>The poligono.hbm.xml<br>...<br> <property name="Poli" type="org.hibernatespatial.GeometryUserType"><br>
<column name="f0209_poli" sql-type="geometry"><br> <comment>Poligono</comment><br> </column><br> </property><br>...<br><br>The Poligono.java<br>
...<br>import com.vividsolutions.jts.geom.Geometry;<br>...<br> private Geometry poli;<br>...<br><br><br>What is wrong?<br><br>Thank you for help.<br><br>Att,<br><br>Paulo Angelo<br></div>