Is the first time that i use spring and hibernate starting from the basics,
i need to get geometries from a postgis table populated with Qgis.
I generate a persistence mapping of the table with jpaData model,
@Entity @Table(name = "comuni_2015", schema = "public", catalog = "springgis") public class Geomcomuni { private int id; private Integer codReg; private Integer codCm; private Integer codPro; private Integer proCom; private String comune; private String nomeTed; private Integer flagCm; private Double shapeLeng; private Double shapeArea; @Type(type = "org.hibernate.spatial.GeometryType") private MultiPolygon geom; @Id @Column(name = "id") public int getId() { return id; } public void setId(int id) { this.id = id; } @Type(type = "org.hibernate.spatial.GeometryType") @Column(name = "geom") public MultiPolygon getGeom() { return geom; } @Type(type = "org.hibernate.spatial.GeometryType") public void setGeom(MultiPolygon geom) { this.geom = geom; } @Basic @Column(name = "cod_reg") public Integer getCodReg() { return codReg; } public void setCodReg(Integer codReg) { this.codReg = codReg; } @Basic @Column(name = "cod_cm") public Integer getCodCm() { return codCm; } public void setCodCm(Integer codCm) { this.codCm = codCm; } @Basic @Column(name = "cod_pro") public Integer getCodPro() { return codPro; } public void setCodPro(Integer codPro) { this.codPro = codPro; } @Basic @Column(name = "pro_com") public Integer getProCom() { return proCom; } public void setProCom(Integer proCom) { this.proCom = proCom; } @Basic @Column(name = "comune") public String getComune() { return comune; } public void setComune(String comune) { this.comune = comune; } @Basic @Column(name = "nome_ted") public String getNomeTed() { return nomeTed; } public void setNomeTed(String nomeTed) { this.nomeTed = nomeTed; } @Basic @Column(name = "flag_cm") public Integer getFlagCm() { return flagCm; } public void setFlagCm(Integer flagCm) { this.flagCm = flagCm; } @Basic @Column(name = "shape_leng") public Double getShapeLeng() { return shapeLeng; } public void setShapeLeng(Double shapeLeng) { this.shapeLeng = shapeLeng; } @Basic @Column(name = "shape_area") public Double getShapeArea() { return shapeArea; } public void setShapeArea(Double shapeArea) { this.shapeArea = shapeArea; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Geomcomuni that = (Geomcomuni) o; if (id != that.id) return false; if (geom != null ? !geom.equals(that.geom) : that.geom != null) return false; if (codReg != null ? !codReg.equals(that.codReg) : that.codReg != null) return false; if (codCm != null ? !codCm.equals(that.codCm) : that.codCm != null) return false; if (codPro != null ? !codPro.equals(that.codPro) : that.codPro != null) return false; if (proCom != null ? !proCom.equals(that.proCom) : that.proCom != null) return false; if (comune != null ? !comune.equals(that.comune) : that.comune != null) return false; if (nomeTed != null ? !nomeTed.equals(that.nomeTed) : that.nomeTed != null) return false; if (flagCm != null ? !flagCm.equals(that.flagCm) : that.flagCm != null) return false; if (shapeLeng != null ? !shapeLeng.equals(that.shapeLeng) : that.shapeLeng != null) return false; if (shapeArea != null ? !shapeArea.equals(that.shapeArea) : that.shapeArea != null) return false; return true; } @Override public int hashCode() { int result = id; result = 31 * result + (geom != null ? geom.hashCode() : 0); result = 31 * result + (codReg != null ? codReg.hashCode() : 0); result = 31 * result + (codCm != null ? codCm.hashCode() : 0); result = 31 * result + (codPro != null ? codPro.hashCode() : 0); result = 31 * result + (proCom != null ? proCom.hashCode() : 0); result = 31 * result + (comune != null ? comune.hashCode() : 0); result = 31 * result + (nomeTed != null ? nomeTed.hashCode() : 0); result = 31 * result + (flagCm != null ? flagCm.hashCode() : 0); result = 31 * result + (shapeLeng != null ? shapeLeng.hashCode() : 0); result = 31 * result + (shapeArea != null ? shapeArea.hashCode() : 0); return result; } } a simple DAO class
@Repository public interface GeomcomuniDao extends CrudRepository<Geomcomuni, Long> { Geomcomuni findById(int id); } and below the App starter
public class App { public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "applicationContext.xml"); GeomcomuniDao geomcomuniDao = context.getBean(GeomcomuniDao.class); System.out.println("Get second geometry: " + geomcomuniDao.findById(2)); } } These are the last lines of the output
INFO: HHH000261: Table found: public.comuni_2015 mag 01, 2016 1:16:43 PM org.hibernate.tool.hbm2ddl.TableMetadata INFO: HHH000037: Columns: [flag_cm, shape_area, pro_com, comune, cod_pro, id, cod_cm, geom, nome_ted, cod_reg, shape_leng]
Get second geometry: com.devcrumb.model.Geomcomuni@8ed21ebb
Process finished with exit code 0
As you can see it returns me a strange alphanumeric string, how can i get a string format of the row for example?