|
|
|
Scheidt
|
Hi
i'm following the basic tutorial available in hibernate spacial site. I just, change the class xml file for anottations, like this: import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinColumns; import javax.persistence.ManyToOne; import javax.persistence.SequenceGenerator; import javax.persistence.Table; import org.hibernate.annotations.Type; @Entity @Table(name="gis_point") @org.hibernate.annotations.Proxy(lazy=false) public class GisPoint { @Id @SequenceGenerator(name="seqGisPoint", sequenceName="gis_point_id_seq", allocationSize=1) @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqGisPoint") @Column(name="id") private Long id; @Column(name="name", nullable=true, length=50) private String name; @Column(name="the_geom") @Type(type="org.hibernatespatial.GeometryUserType") private com.vividsolutions.jts.geom.Point theGeom; @ManyToOne(cascade={ CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH }) @JoinColumns({ @JoinColumn(name="place_id", referencedColumnName="id") }) @Basic(fetch=FetchType.LAZY) private org.ctm.value.Place place; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public com.vividsolutions.jts.geom.Point getTheGeom() { return theGeom; } public void setTheGeom(com.vividsolutions.jts.geom.Point theGeom) { this.theGeom = theGeom; } public org.ctm.value.Place getPlace() { return place; } public void setPlace(org.ctm.value.Place place) { this.place = place; } } this class "GisPoint" its mapped for a table int postgresql with postgis, everthing working fine with sql inserts commands. But when running througth hibernate spatial, hibernate is throwing this exception: 08:26:24,952 INFO SessionFactoryImpl:161 - building session factory 08:26:26,143 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured Hibernate: select nextval ('gis_point_id_seq') Hibernate: insert into gis_point (name, place_id, the_geom, id) values (?, ?, ?, ?) Exception in thread "main" java.lang.NoSuchFieldError: srid at org.hibernatespatial.postgis.PGGeometryUserType.convertJTSPoint(PGGeometryUserType.java:353) at org.hibernatespatial.postgis.PGGeometryUserType.conv2DBGeometry(PGGeometryUserType.java:262) at org.hibernatespatial.AbstractDBGeometryType.nullSafeSet(AbstractDBGeometryType.java:153) at org.hibernatespatial.GeometryUserType.nullSafeSet(GeometryUserType.java:184) at org.hibernate.type.CustomType.nullSafeSet(CustomType.java:146) at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2002) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2248) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2665) at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:60) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106) at org.ctm.util.AppTeste2.main(AppTeste2.java:67) The main App is: import org.ctm.hibernate.HiberUtil; import org.ctm.value.Place; import org.ctm.value.gis.GisPoint; import org.hibernate.Session; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.Point; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.io.WKTReader; import com.vividsolutions.jts.io.ParseException; public class AppTeste2 { public static void main(String[] args) { double dxxlat = -24.996118d; double dxxlong = -53.337017d; Coordinate ct = new Coordinate(dxxlat, dxxlong,0d); GeometryFactory geometryFactory = new GeometryFactory(); Point point = geometryFactory.createPoint( ct ); point.setSRID(4326); String wktPoint = point.toString(); //First interpret the WKT string to a point WKTReader fromText = new WKTReader(); Geometry geom = null; try{ geom = fromText.read(wktPoint); } catch (ParseException e){ throw new RuntimeException("Not a WKT string:" + wktPoint); } if (!geom.getGeometryType().equals("Point")){ throw new RuntimeException("Geometry must be a point. Got a " + geom.getGeometryType()); } Session session = HiberUtil.currentSession(); session.beginTransaction(); GisPoint gp = new GisPoint(); gp.setId(100L); gp.setName("qwerqwer"); gp.setTheGeom((Point)geom); Place pl = new Place(); pl.setId(6L); gp.setPlace(pl); session.save(gp); session.getTransaction().commit(); } } I tried througth xml conf file too, and the same error persists. Please, any help will be apreciate. Tranks in advance. _______________________________________________ hibernatespatial-users mailing list [hidden email] http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users |
||||||||||||||||
|
Karel Maesen
|
Hi,
It looks like you are using either a rather old, or a very new postgis.jar. Could you get post the version of postgis you're using? Regards, Karel Maesen On 17 Jun 2008, at 14:59, Felippe Scheidt wrote: > Hi > i'm following the basic tutorial available in hibernate spacial > site. I just, change the class xml file for anottations, like this: > > import javax.persistence.Basic; > import javax.persistence.CascadeType; > import javax.persistence.Column; > import javax.persistence.Entity; > import javax.persistence.FetchType; > import javax.persistence.GeneratedValue; > import javax.persistence.GenerationType; > import javax.persistence.Id; > import javax.persistence.JoinColumn; > import javax.persistence.JoinColumns; > import javax.persistence.ManyToOne; > import javax.persistence.SequenceGenerator; > import javax.persistence.Table; > import org.hibernate.annotations.Type; > > @Entity > @Table(name="gis_point") > @org.hibernate.annotations.Proxy(lazy=false) > public class GisPoint { > > @Id > @SequenceGenerator(name="seqGisPoint", > sequenceName="gis_point_id_seq", allocationSize=1) > @GeneratedValue(strategy=GenerationType.SEQUENCE, > generator="seqGisPoint") > @Column(name="id") > private Long id; > > @Column(name="name", nullable=true, length=50) > private String name; > > @Column(name="the_geom") > @Type(type="org.hibernatespatial.GeometryUserType") > private com.vividsolutions.jts.geom.Point theGeom; > > @ManyToOne(cascade={ CascadeType.MERGE, CascadeType.PERSIST, > CascadeType.REFRESH }) > @JoinColumns({ @JoinColumn(name="place_id", > referencedColumnName="id") }) > @Basic(fetch=FetchType.LAZY) > private org.ctm.value.Place place; > > > public Long getId() { > return id; > } > > public void setId(Long id) { > this.id = id; > } > > public String getName() { > return name; > } > > public void setName(String name) { > this.name = name; > } > > public com.vividsolutions.jts.geom.Point getTheGeom() { > return theGeom; > } > > public void setTheGeom(com.vividsolutions.jts.geom.Point > theGeom) { > this.theGeom = theGeom; > } > > public org.ctm.value.Place getPlace() { > return place; > } > > public void setPlace(org.ctm.value.Place place) { > this.place = place; > } > > } > > this class "GisPoint" its mapped for a table int postgresql with > postgis, everthing working fine with sql inserts commands. But when > running througth hibernate spatial, hibernate is throwing this > exception: > > 08:26:24,952 INFO SessionFactoryImpl:161 - building session factory > 08:26:26,143 INFO SessionFactoryObjectFactory:82 - Not binding > factory to JNDI, no JNDI name configured > Hibernate: select nextval ('gis_point_id_seq') > Hibernate: insert into gis_point (name, place_id, the_geom, id) > values (?, ?, ?, ?) > Exception in thread "main" java.lang.NoSuchFieldError: srid > at > org.hibernatespatial.postgis.PGGeometryUserType.convertJTSPoint > (PGGeometryUserType.java:353) > at > org.hibernatespatial.postgis.PGGeometryUserType.conv2DBGeometry > (PGGeometryUserType.java:262) > at org.hibernatespatial.AbstractDBGeometryType.nullSafeSet > (AbstractDBGeometryType.java:153) > at org.hibernatespatial.GeometryUserType.nullSafeSet > (GeometryUserType.java:184) > at org.hibernate.type.CustomType.nullSafeSet(CustomType.java:146) > at > org.hibernate.persister.entity.AbstractEntityPersister.dehydrate > (AbstractEntityPersister.java:2002) > at org.hibernate.persister.entity.AbstractEntityPersister.insert > (AbstractEntityPersister.java:2248) > at org.hibernate.persister.entity.AbstractEntityPersister.insert > (AbstractEntityPersister.java:2665) > at org.hibernate.action.EntityInsertAction.execute > (EntityInsertAction.java:60) > at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279) > at org.hibernate.engine.ActionQueue.executeActions > (ActionQueue.java:263) > at org.hibernate.engine.ActionQueue.executeActions > (ActionQueue.java:167) > at > org.hibernate.event.def.AbstractFlushingEventListener.performExecution > s(AbstractFlushingEventListener.java:298) > at org.hibernate.event.def.DefaultFlushEventListener.onFlush > (DefaultFlushEventListener.java:27) > at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000) > at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java: > 338) > at org.hibernate.transaction.JDBCTransaction.commit > (JDBCTransaction.java:106) > at org.ctm.util.AppTeste2.main(AppTeste2.java:67) > > > The main App is: > > > > import org.ctm.hibernate.HiberUtil; > import org.ctm.value.Place; > import org.ctm.value.gis.GisPoint; > import org.hibernate.Session; > import com.vividsolutions.jts.geom.Coordinate; > import com.vividsolutions.jts.geom.GeometryFactory; > import com.vividsolutions.jts.geom.Point; > import com.vividsolutions.jts.geom.Geometry; > import com.vividsolutions.jts.io.WKTReader; > import com.vividsolutions.jts.io.ParseException; > > > public class AppTeste2 { > > public static void main(String[] args) { > > > double dxxlat = -24.996118d; > double dxxlong = -53.337017d; > > Coordinate ct = new Coordinate(dxxlat, dxxlong,0d); > > GeometryFactory geometryFactory = new GeometryFactory(); > Point point = geometryFactory.createPoint( ct ); > point.setSRID(4326); > > String wktPoint = point.toString(); > > > //First interpret the WKT string to a point > WKTReader fromText = new WKTReader(); > Geometry geom = null; > try{ > geom = fromText.read(wktPoint); > } catch (ParseException e){ > throw new RuntimeException("Not a WKT string:" + > wktPoint); > } > if (!geom.getGeometryType().equals("Point")){ > throw new RuntimeException("Geometry must be a > point. Got a " + geom.getGeometryType()); > } > > Session session = HiberUtil.currentSession(); > > session.beginTransaction(); > > GisPoint gp = new GisPoint(); > gp.setId(100L); > gp.setName("qwerqwer"); > gp.setTheGeom((Point)geom); > Place pl = new Place(); > pl.setId(6L); > gp.setPlace(pl); > > session.save(gp); > > session.getTransaction().commit(); > > } > } > > > > I tried througth xml conf file too, and the same error persists. > Please, any help will be apreciate. > > Tranks in advance. > > > _______________________________________________ > hibernatespatial-users mailing list > [hidden email] > http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/ > hibernatespatial-users _______________________________________________ hibernatespatial-users mailing list [hidden email] http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users |
||||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |