3

One of the column is of the type XMLTYPE in Oracle database. In my application, I want to persist the data and using Hibernate.

I did the following for mapping XMLTYPE in hibernate

  1. Define the custom user type implementing UserType

  2. The custom user type implementation is based on the blog link - http://community.jboss.org/wiki/MappingOracleXmlTypetoDocument

  3. ut we are not using C3p0 connection pool and instead we are using DBCP

I am facing issue while creating the XMLType in the custom user type

XMLType.createXML(st.getConnection(),HibernateXMLType.domToString((Document) value));

where st is the preparedStatement passed to the method.

The connection object returned by st.getConnection() is of the type org.apache.commons.dbcp.PoolableConnection

But the createXML method expects connection object only of the type oracle.jdbc.OracleConnection

I also tried getting the getInnermostDelegate but this also does not work.

The XMLTYPE creation methods are in the included jar xdb.jar - will there be any changes depending on the versions included?

Thanks

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Got the SQLConnection object using the below code-

SimpleNativeJdbcExtractor extractor = new SimpleNativeJdbcExtractor();
PoolableConnection poolableConnection = (PoolableConnection) extractor
                .getNativeConnection(st.getConnection());
Connection sqlConnection = poolableConnection.getInnermostDelegate();

Now, the error message is java.sql.SQLException: Invalid column type

Below is the over ridden method

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");
        }
    }

Left with no clue now...

4

2 に答える 2

0

Java から XMLType を使用して多くの問題に直面しましたが、この問題は非常に簡単な方法で修正しました。

入力データ型を Oracle DB 側から XMLtype から CLOB に変更した後、ストアド プロシージャの最初の行で CLOB を簡単に渡します。CLOB から XMLType を作成しました。

CLOB は Java では非常に単純です。文字列 ( statement.setString(1, string);)として使用するだけです。

于 2012-12-30T08:13:13.467 に答える
0

これと同じ問題を解決しましたが、XMLType 列をエンティティの java.lang.String にマップしたため、ソリューションが簡素化されました。

別の質問への回答として、詳細な段階的な解決策を残しました。

于 2013-08-16T21:08:41.503 に答える