【发布时间】:2011-04-18 15:53:16
【问题描述】:
其中一列是 Oracle 数据库中的 XMLTYPE 类型。 在我的应用程序中,我想保留数据并使用 Hibernate。
我为在休眠中映射 XMLTYPE 做了以下操作
定义实现 UserType 的自定义用户类型
自定义用户类型实现基于博客链接-http://community.jboss.org/wiki/MappingOracleXmlTypetoDocument
我们没有使用 C3p0 连接池,而是使用 DBCP
在自定义用户类型中创建 XMLType 时遇到问题
XMLType.createXML(st.getConnection(),HibernateXMLType.domToString((Document) value));
其中 st 是传递给方法的preparedStatement。
st.getConnection() 返回的连接对象的类型是 org.apache.commons.dbcp.PoolableConnection
但是 createXML 方法只需要 oracle.jdbc.OracleConnection 类型的连接对象
我也尝试获取 getInnermostDelegate 但这也不起作用。
XMLTYPE 创建方法在包含的 jar xdb.jar 中 - 根据包含的版本会有任何变化吗?
谢谢
++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++
使用以下代码获取 SQLConnection 对象-
SimpleNativeJdbcExtractor extractor = new SimpleNativeJdbcExtractor();
PoolableConnection poolableConnection = (PoolableConnection) extractor
.getNativeConnection(st.getConnection());
Connection sqlConnection = poolableConnection.getInnermostDelegate();
现在,错误消息是 java.sql.SQLException: Invalid column type
下面是被覆盖的方法
public void nullSafeSet(PreparedStatement st, Object value, int index)
throws HibernateException, SQLException {
SimpleNativeJdbcExtractor extractor = new SimpleNativeJdbcExtractor();
PoolableConnection poolableConnection = (PoolableConnection) extractor
.getNativeConnection(st.getConnection());
Connection sqlConnection = poolableConnection.getInnermostDelegate();
try {
XMLType xmlType = null;
if (value != null) {
xmlType.createXML(sqlConnection, HibernateXMLType
.domToString((Document) value));
}
st.setObject(index, xmlType);
} catch (Exception e) {
e.printStackTrace();
throw new SQLException(
"Could not convert Document to String for storage");
}
}
现在一无所知...
【问题讨论】:
-
"我也尝试获取 getInnermostDelegate,但这也不起作用。"我总是使用 getInnermostDelegate();它有效。请使用 getInnermostDelegate/* Connection oracleConnection = conn 发送错误; if (conn instanceof org.apache.commons.dbcp.DelegatingConnection) { oracleConnection = ((org.apache.commons.dbcp.DelegatingConnection)conn).getInnermostDelegate(); } */
标签: java oracle hibernate ora-17004