1

I'm using Spring with Hibernate Spatial 5.0.12 and trying to persist a com.vividsolutions.jts.geom.Geometry object to an Oracle database with SDO_GEOMETRY column but get this exception when trying to save it to the db:

ORA-00932: Inconsistent datatypes: expected MDSYS.SDO_GEOMETRY got BINARY

I haven't found this problem anywhere else and have no idea how to solve it as I'm new to hibernate.

This is the entity I'm trying to save:

@Entity
@Table(name = "DETECTED_OBJECTS")
public class DetectedObject {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "DETECTED_SEQ")
    @SequenceGenerator(sequenceName = "detected_seq", allocationSize = 1, name = "DETECTED_SEQ"_
    private Long id;
    private Geometry polygon;

    public DetectedObject(){}

    public DetectedObject(Coordinate[] coordinates){
    this.polygon = new GeometryFactory().createPolygon(coordinates);
    }
}

And this is my hibernate config:

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.Oracle10gDialect
spring.jpa.properties.provider_class = org.hibernate.cache.NoCacheProvider
spring.jpa.hibernate.ddl-auto = update
spring.jpa.properties.hibernate.format-sql = true

And the actual line that throws the exception:

detectedObjectRepository.save(detectedObject)

2 Answers2

2

Please add the below configs in application.properties:

spring.jpa.properties.hibernate.dialect = org.hibernate.spatial.dialect.oracle.OracleSpatial10gDialect

spring.datasource.type=oracle.jdbc.pool.OracleDataSource

If this doesn't work, use geolatte library and below properties in model:

private Point<G2D> point;
private Polygon<G2D> polygon;
adiga
  • 34,372
  • 9
  • 61
  • 83
shkna 1368
  • 21
  • 3
1

The Solution was to explicitly tell spring I'm using a spatial dialect with hibernate by changing this line:

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.Oracle10gDialect

to this:

spring.jpa.properties.hibernate.dialect = org.hibernate.spatial.dialect.oracle.OracleSpatial10gDialect