将MDSYS.SDO_GEOMETRY列值读取到JAVA实体失败导致错误的列类型

时间:2018-08-28 13:45:40

标签: java oracle hibernate geometry oracle-spatial

我正在使用hibernate 4.1.12,并尝试在我的JAVA实体中使用Oracle数据库中的MDSYS.SDO_GEOMETRY列。

在pom.xml中,我有:

<dependency>
    <groupId>oracle</groupId>
    <artifactId>sdoapi</artifactId>
    <version>11.2.0</version>
</dependency>

在实体中,我有:

@Column(name = "GEOMETRY", nullable = false)
private JGeometry geometry;

启动应用程序时,我将在验证过程中得到以下提示:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [META-INF/spring/jpa-em-config.xml]: 

Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: mapperPU] Unable to build EntityManagerFactory

Caused by: org.hibernate.HibernateException: Wrong column type in DB_USER1.WORK_AREA for column GEOMETRY.
Found: sdo_geometry, expected: raw(255)

也许这不是将MDSYS.SDO_GEOMETRY列读取到JAVA实体的正确方法吗?应该怎么做?

1 个答案:

答案 0 :(得分:0)

使用Oracle10gDialect和以下定义,它在我的情况下有效。

import com.vividsolutions.jts.geom.Geometry;

@Type(type = "org.hibernate.spatial.GeometryType")
@Column(name = "GEOMETRY", columnDefinition = "MDSYS.SDO_GEOMETRY")
public Geometry getGeometry() {
    return this.geometry;
}