使用openjpa 2.2.2映射oracle XMLTYPE

时间:2016-11-27 15:18:15

标签: java oracle jpa openjpa

实体java代码:

 @Column(name="XMLCOL", columnDefinition="XMLTYPE") 
    private String xmlcol;

public String getXmlcol() {
    return xmlcol;
}

public void setXmlcol(String xmlcol) {
    this.xmlcol = xmlcol;
}

表列数据类型:

XMLCOL   PUBLIC.XMLTYPE STORAGE BINAR

每次我将xml数据作为NULL。无法获取数据。

尝试@ColumnTransformer(read = "to_clob(columnName)", write = "?")但没有工作。也低于异常

Exception in thread "main" <openjpa-2.2.2-r422266:1468616 fatal user error> org.apache.openjpa.persistence.ArgumentException: "com.javawebtutor.Supplier.xmlcol" declares a column that is not compatible with the expected type "varchar".  Column details:
Full Name: Supplier.XMLCOL
Type: unknown(2009)
Size: 2000
Default: null
Not Null: false

添加persistence.xml

    <?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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_2_0.xsd">
    <persistence-unit name="jpa">
        <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
        <class>com.javawebtutor.Supplier</class>
        <properties>
            <property name="openjpa.jdbc.SchemaFactory" value="native"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@localhost:1521:xe"/>
            <property name="javax.persistence.jdbc.user" value="***"/>
            <property name="javax.persistence.jdbc.password" value="***"/>
            <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
            <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
              <property name="openjpa.RuntimeUnenhancedClasses" value="supported"/>
        </properties>
    </persistence-unit>
</persistence>

提前致谢。

1 个答案:

答案 0 :(得分:0)

更改ojdbc6.jar后问题得到解决..使用11g ojdbc6.jar而不是12c