无法从PreparedStatement获取OracleSpatial Connection对象

时间:2017-12-11 12:47:51

标签: hibernate hikaricp oracle-spatial hibernate-spatial

我正在使用hibernate spatial 4.3.2和hibernate 4.3.11,我的db是oracle 12c。 我使用hikariCP连接池。当我使用hikacriCP我得到一个错误,似乎原因是hibernate空间无法访问hikari连接实例的包装连接,这是我的例外: 问题是,在保存包含几何字段的实体时,hibernate会抛出错误。

Couldn't get at the OracleSpatial Connection object from the PreparedStatement

当我删除hikari时,一切都很好! 这是我的实体和xml映射文件。

<hibernate-mapping>
    <class   name="MyPoint"  table="MyPoint"  >
        <id name="id" type="long" >
            <column name="ID"  />
            <generator class="sequence" >
                <param name="sequence">SEQ_MyPoint</param>
            </generator>
        </id>
        <property           name="name"             column="name"               type="string"                                           not-null="true" />
        <property           name="geom"             column="geom"               type="org.hibernate.spatial.GeometryType"               not-null="true" />

    </class>
</hibernate-mapping>


public class MyPoint extends BaseEntity<Long> {
    private String name;
    private Point geom;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Point getGeom() {
        return geom;
    }

    public void setGeom(Point geom) {
        this.geom = geom;
    }
}

以下是保存实体的代码:

 Geometry geom = wktToGeometry(wkt);
 geom.setSRID(4326);
 MyPoint p= new  MyPoint();
 p.setName("some one");
 p.setGeom((Point) geom);
 repository.save(p);

yml中的hibernate空间配置:

 jpa:
    open-in-view: false
    hibernate:
      ddl-auto: update
      naming:
        strategy: org.hibernate.cfg.ImprovedNamingStrategy
    properties:
      hibernate:
        dialect: org.hibernate.spatial.dialect.oracle.OracleSpatial10gDialect
        default_schema: my_schema
        show_sql: true
        current_session_context_class: org.springframework.orm.hibernate4.SpringSessionContext
        spatial:
           ogc_strict: true
           connection_finder: org.hibernate.spatial.dialect.oracle.DefaultConnectionFinder

这是我的stacktrace:

Caused by: org.hibernate.HibernateException: Problem finding Oracle Connection
    at org.hibernate.spatial.dialect.oracle.OracleJDBCTypeFactory.createStruct(OracleJDBCTypeFactory.java:123)
    at org.hibernate.spatial.dialect.oracle.SDOGeometryValueBinder.store(SDOGeometryValueBinder.java:76)
    at org.hibernate.spatial.dialect.oracle.SDOGeometryValueBinder.toNative(SDOGeometryValueBinder.java:83)
    at org.hibernate.spatial.dialect.oracle.SDOGeometryValueBinder.bind(SDOGeometryValueBinder.java:66)
    at org.hibernate.spatial.dialect.oracle.SDOGeometryValueBinder.bind(SDOGeometryValueBinder.java:52)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:286)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:281)
    at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:56)
    at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2843)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3121)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3581)
    at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:104)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:465)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:351)
    at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350)
    at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)
    at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1258)
    at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:425)
    at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
    at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:177)
    at org.springframework.orm.hibernate4.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:584)
    ... 138 more
Caused by: org.hibernate.spatial.helper.FinderException: Couldn't get at the OracleSpatial Connection object from the PreparedStatement.
    at org.hibernate.spatial.dialect.oracle.DefaultConnectionFinder.find(DefaultConnectionFinder.java:103)
    at org.hibernate.spatial.dialect.oracle.DefaultConnectionFinder.find(DefaultConnectionFinder.java:44)
    at org.hibernate.spatial.dialect.oracle.OracleJDBCTypeFactory.createStruct(OracleJDBCTypeFactory.java:121)
    ... 158 more

2017-12-11 16:10:00 INFO  o.h.e.j.b.internal.AbstractBatchImpl - HHH000010: On release of batch it still contained JDBC statements

2 个答案:

答案 0 :(得分:0)

我有同样的问题并通过提供我自己的Connection finder接口实现并在hibernate.spatial.connection_finder属性中配置它来解决它。

要从Hikari获取oracle.jdbc.driver.OracleConnection,您可以使用:

((HikariProxyConnection) connection).unwrap(OracleConnection.class);

答案 1 :(得分:0)

我终于通过扩展DefaultConnectionFinder并覆盖了find方法解决了该问题:

$('#sbts').click(function(){
    var sdate = $("#datepicker").val();
    var edate = $("#datepicker2").val();
    var data= { action: 'sharepricedownload', 'sdate' :sdate, 'edate':edate};
    jQuery.post(ajaxurl, data,function(response) {   
     window.open('<?php echo home_url('/'); ?>wp-admin/admin-ajax.php?action=sharepricedownload', 'myNewPage');
     });
   });