I basically encounter the same problem described in this post: hibernate-spatial-4.0 creates bytea column type instead of geometry
According to the hibernate docs the type mapping of a jts Geometry object should be done automatically without any additional annotations required. However, i end up with the bytea type in my postgis database: Database result
I use Spring boot 3.2, hibernate 6.3.1.Final and jts 1.19. My model is defined as:
import org.locationtech.jts.geom.Geometry;
// ...
@NoArgsConstructor
@AllArgsConstructor
@Data
@Entity
@Builder
public class DwdPoiStation {
/** the internal database id. */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
// ...
@Column
private Geometry geom;
/** the height. */
@Column
private float height;
}
And i have set the hibernate dialect accordingly:
spring.jpa.database-platform: org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto: update
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults: false
spring.jpa.properties.hibernate.default_schema: public
For the database i use a kartoza/postgis:16-3.4 docker image. The PostgreSQL jdbc driver version is 42.7.1.
What am i missing?
I tried one of the solution provided in the other post (https://stackoverflow.com/a/60469891/10209352), checked my dependencies and used the latest jts library. I also searched online for other solutions, but were unable to even find a related problem using the hibernate 6.x version. Since the official documentation states that additional annotations are not required, i expect that i do not have to use properties like "columnDefinition" or annotations like @Type to make this work. It rather seems to be a version missmatch problem.
Somehow the hibernate-spatial jar did not end up in my classpath. Now everything works like a charm. Thanks Karel for pointing that out!