【发布时间】:2018-03-20 09:03:19
【问题描述】:
有一个表格,其中包含一个SDO_GEOMETRY 类型的列,代表一些点。稍后将执行诸如“显示距离 x 内的所有其他点”之类的空间查询。
在通过sqlloader 将一些数据泵入导入表后,如果业务密钥仍然存在,我将在合并时将这些数据集放入基表中。
我的应用程序是一个使用hibernate 5.0.9、hibernate-spatial 5.0.9 final、Oracle12c 数据库和hibernate.dialect 的可执行jar
org.hibernate.dialect.Oracle12cDialect
以前但现在改为
org.hibernate.spatial.dialect.oracle.OracleSpatial10gDialect
我知道 Oracle10 官方只有一种空间方言,而且 oracle11 和 oracle12 也有 testet。
现在的问题是,对象通过休眠存储到基表中,但在 SDO-Geometry 内部,所有坐标均为空(而 sdo_geometry 对象不存在)。
select
businessKey,
my_sdo_geometry.sdo_point.x longitude,
my_sdo_geometry.sdo_point.y latitude
from my_import_table;
在sqlloader之后,import-table中的所有坐标都显示好了。
但在处理完每个导入数据集后,它的“导入”列 {Y, N} 设置为“Y”。这样做我正在使用myEntityManager.merge(importDataset)。由于这个原因(尽管在 sqlloader 之后所有坐标都很好),导入数据集的坐标被清除为 null。
//coordinates still viewable in database
importObject.setImported(Boolean.TRUE);
em.merge(importObject);
//coordinates null now
我猜是空间方言不能正常工作。 我担心这是由于最后一个版本的 hibernate-spatial 和 oracle12c 之间的一些不兼容而发生的。
我在这里写信是希望有人成功地使用了 oracle12 的 hibernate-spatial(以澄清它是可能的),并且可以就我这边的任何错误配置获得一些帮助。
我的应用程序的persistance.xml:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="myUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.ejb.cfgfile" value="/hibernate.cfg.xml" />
<property name="use_sql_comments" value="true" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="false" />
<property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver" />
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@123.456.789.1:1234/cm" />
<property name="hibernate.connection.username" value="testMe" />
<property name="hibernate.connection.password" value="********" />
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle12cDialect" />
</properties>
</persistence-unit> </persistence>
提前致谢。
编辑: 在实体类中,sdo_geometry 列(这里称为 'Position')getter 注释如下:
@Column(name = "POSITION", nullable = false)
public Point getPosition() {
return this.position;
}
编辑 2: 启用hibernate sql trace后,我发现hibernate正在尝试这个更新:
Hibernate: update IMPORT_TABLE set HB_VERSION=?, BUSINESS_KEY=?, IMPORTED=?, [...], POSITION=? where IMPORT_TABLE_ID=? and HB_VERSION=?
我指的是POSITION=?,我认为这不可能。
在这个位置,我希望发生休眠方言。
可能会再次暗示与 hibernate-dialect spatial10 和 oracle12 不兼容。
【问题讨论】:
标签: java hibernate oracle12c hibernate-spatial