Search code examples
javahibernategeometryhibernate-mappingpostgis

hibernate spatial error: type "geometry" does not exist


I want to use hibernate spatial to handle my spatial objects.I am using hibernate-spatial-4.0.1 with hibernate 4.2. My dialect:

<property name="hibernate.dialect"> org.hibernate.spatial.dialect.postgis.PostgisDialect</property>

I have an Entity like this:

@Entity
@DiscriminatorValue(CK.LAYER_PICTURES)
public class PicsLayerItem extends LayerItem {

   @Column(name = "place_name")
   private String placeName;

   public void setPlaceName(String name) {
       this.placeName = name;
   }

   public String getPlaceName() {
       return this.placeName;
   }


   @Type(type = "org.hibernate.spatial.GeometryType")
   @Column(name = "locations", nullable = true)
   private LineString locations;

   public LineString getLocations() {
       return locations;
   }
}

The problem that when hibernate updates schema, it faced this error:

ERROR [http-nio-8084-exec-53] org.hibernate.tool.hbm2ddl.SchemaUpdate.execute HHH000388: Unsuccessful: alter table public.tree_item add column locations GEOMETRY
ERROR [http-nio-8084-exec-53] org.hibernate.tool.hbm2ddl.SchemaUpdate.execute ERROR: type "geometry" does not exist

I guess my postgresql does not support the geomtry types. I use PgAdminIII. It is postgis. It supports data types like polygon.

enter image description here

What can I do solving this problem?
Similar question with no answer: Type geometry not found with postgis and hibernate-spatial


Solution

  • Your Postgresql does not support geometry. You need to add postgis extension to it in order to create spatial databases. So download suitable postgis extension for your postgresql from here. Then install it in the postgresql installation folder exactly, for example (in my system) in the following path:

     C:\Program Files (x86)\OpenGeo\OpenGeo Suite\pgsql\9.1