1

I am working with application which uses spring 3.1 and hibernate 4.2. For spatial feature we are planning to use hibernate spatial with postgis. But hibernate spatial creates column with bytea type instead of geometry. I am not able to find out where is root cause of this. I spend already couple of days in resolving but not successful.

hibernate-spatial-4.0.jar is used.

I am using following hibernate.properties file

database.driverClassName=org.postgresql.Driver database.url=jdbc:postgresql://127.0.0.1:5433/mpdb database.username=postgres database.password=postgres hibernate.dialect=org.hibernate.spatial.dialect.postgis.PostgisDialect hibernate.show_sql=true hibernate.hbm2ddl.auto=update 

I am using following annotation in Entity

 @Column(columnDefinition="Geometry", nullable = true) @Type(type = "org.hibernate.spatial.GeometryType") private Point geom; 

Application successfully creates following table but instead of geometry type it creates bytea for column geom

 Table "public.tile" Column | Type | Modifiers ----------------------------+-----------------------------+----------- id | integer | not null alt | double precision | not null geom | bytea | lat | double precision | not null lng | double precision | not null multipath_table | text | not null multipath_table_min_value | double precision | multipath_table_resolution | integer | multipath_table_tx_id | text | tile_created | timestamp without time zone | not null tile_data_age | integer | tile_data_present | text | not null tile_num_tx | integer | Indexes: "tile_pkey" PRIMARY KEY, btree (id) 

However manually I am able to create Geometry type column in postgis2.2-postgres9.5 database

I went through almost every thread but unsuccessful. Need help.

2 Answers 2

2

I could able to fix this issue by modifying annotations used in Entity class. This works for me. @Column(columnDefinition="geometry(Point,4326)") private org.hibernate.spatial.GeometryType geom;

Sign up to request clarification or add additional context in comments.

Comments

2

PostgisDialect registers JTS or Geolatte Point types (refer to the Hibernate spatial documentation and the sources. In case of JTS make sure you use an up to date version (org.locationtech.jts) rather than the old one (com.vividsolutions.jts) by updating your dependencies and checking your imports (I had both, the old and the new dependency on my classpath and accidently imported the wrong one).

A working example (in Kotlin, but getting the Java imports / annotations should be straightforward):

My entity (note: there is no annotation at all on the Point type!):

import org.locationtech.jts.geom.Point import java.time.ZonedDateTime import javax.persistence.* @Entity data class TrackPoint( @Id @GeneratedValue var id: Long? = null, var location : Point, var time : ZonedDateTime, @ManyToOne var track: Track? = null ) 

The maping function to create the TrackPoint which is then persisted:

fun mapWayPoint2TrackPoint(it: WayPoint) : TrackPoint { val coordinate = Coordinate(it.longitude.toDouble(), it.latitude.toDouble(), it.elevation.get().toDouble()) val point = geometryFactory.createPoint(coordinate) return TrackPoint(location = point, time = it.time.get()) } 

Additionally you might use one of the more recent postgis dialects (like PostgisPG95Dialect) since PostgisDialect is deprecated.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.