I'm using Hibernate Spatial in a GIS application. I have an entity class, in which one of the columns is a geometry column, as shown below:
@Entity
@Table(name = "table_name")
public class Admin implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "gid")
private Long id;
@Column(name = "adm1_name")
private String adminName;
@Column(name = "adm1_code")
private String adminCode;
/*private Integer adminLevel;*/
@Column(name = "the_geom")
@Type(type = "org.hibernatespatial.GeometryUserType")
private Geometry geom;
@Column(name = "pmal")
private String pMale;
@Column(name = "pfem")
private String pFemale;
public Admin() {}
/* Getters and Setter here*/
}
I've done a lot of experiments, and I've eliminated hibernate configuration as the cause. I've also eliminated Spring configuration as the cause.
I think my problem may be something to do with the version of hibernate spatial I'm using; I'm using version 4.0-M1. In my earlier experiments, I realized there are some package name changes from versionn 1.x. Other details are as follows:
PostGIS JDBC: version 1.3.3,
Hibernate Core: version 3.6.10 FINAL,
Hibernate Entity Manager: version 3.6.10 FINAL, and
PostgreSQL JDBC: version 8.4-702.jdbc3
Whenever I start my server, application deployment fails with the following error:
org.hibernate.MappingException: Could not determine type for: org.hibernatespatial.GeometryUserType, at table: #table_name# for columns: #geometry_column_name#
Any idea on how I can solve this will be highly appreciated.
Best Answer
The issue is the renaming of the package containing GeometryUserType class in Hibernate Spatial 4.x from
org.hibernatespatial.GeometryUserType
in 1.x toorg.hibernate.spatial.GeometryType
in 4.x. I also changed the PostGIS JDBC driver from 1.3.3 to 1.5.2.So, the geometry property should be defined and mapped thus:
This sorts it out for me.