其中一列是Oracle数据库中的XMLTYPE类型。在我的应用程序中,我希望持久化数据并使用Hibernate。
为了在hibernate中映射XMLTYPE,我做了以下工作
http://community.jboss.org/wiki/MappingOracleXmlTypetoDocument
。
在自定义用户类型中创建XMLType时,我面临问题
XMLType.createXML(st.getConnection(),HibernateXMLType.domToString((Document) value));其中st是传递给方法的preparedStatement。
由org.apache.commons.dbcp.PoolableConnection ()返回的连接对象的类型为st.getConnection
,但是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:无效的列类型
下面是重载的方法
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");
}
}现在毫无头绪地离开了.
发布于 2012-12-30 08:13:13
我在使用java的XMLType时遇到了很多问题,我解决了这个问题是一个非常简单的方法。
我将输入数据类型从oracle DB端更改为XMLtype,然后轻松地传递CLOB和存储过程的第一行;我从CLOB构建了一个XMLType。
CLOB在java中非常直接,只需将其用作字符串(statement.setString(1, string);)即可。
发布于 2013-08-16 21:08:41
我解决了同样的问题,但是将XMLType列映射到实体中的java.lang.String,从而简化了解决方案。
我留下了一个细节,step-by-step solution as an answer to another question。
https://stackoverflow.com/questions/3819135
复制相似问题