2 xuke6677 xuke6677 于 2013.06.03 09:48 提问

mybatis怎么读取oracle xmltype类型的数据

1、oracle 用的是字段类型是xmltype

BOOK_ID     NUMBER              
BOOK_NAME       XMLTYPE             
BOOK_PRICE      NUMBER              

2、JavaBean对应的属性是Object

 private Integer bookId;   
 private Object bookName;
 private Integer bookPrice;

3、mapper.xml 对应jdbcType=CLOB

    <resultMap id="BaseResultMap" type="com.zfy.db.model.Book" >
        <result column="BOOK_ID" property="bookId" jdbcType="INTEGER" />
        <result column="BOOK_PRICE" property="bookPrice" jdbcType="INTEGER" />
      </resultMap>
      <resultMap id="ResultMapWithBLOBs" type="com.zfy.db.model.Book" extends="BaseResultMap" >
        <result column="BOOK_NAME" property="bookName" jdbcType="CLOB" />
      </resultMap>

<!-- 获取Book -->
<select id="selectById" resultMap="ResultMapWithBLOBs">
    select      BOOK_ID, BOOK_PRICE, BOOK_NAME from book where book_id = #{bookId,jdbcType=INTEGER}
  </select>

4、junit 测试报错

static SqlSession session = null;
    @BeforeClass
    public static void before() throws IOException{
        String resource = "mybatis-config.xml";
        Reader reader = Resources.getResourceAsReader(resource);
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(reader);
        session = sessionFactory.openSession();
    }

    @Test 
    public void  selectById() {
        BookMapper mapper= session.getMapper(BookMapper.class);
        Book book = mapper.selectById(1);
        System.out.println(book);
    }

5、报错信息如下

java.lang.NoClassDefFoundError: oracle/xml/binxml/BinXMLException
at oracle.xdb.XMLTypeFactory.create(XMLTypeFactory.java:73)
at oracle.sql.OPAQUE.toClass(OPAQUE.java:376)
at oracle.sql.OPAQUE.toJdbc(OPAQUE.java:318)
at oracle.jdbc.driver.NamedTypeAccessor.getObject(NamedTypeAccessor.java:144)
at oracle.jdbc.driver.NamedTypeAccessor.getObject(NamedTypeAccessor.java:100)
at oracle.jdbc.driver.OracleResultSetImpl.getObject(OracleResultSetImpl.java:921)
at oracle.jdbc.driver.OracleResultSet.getObject(OracleResultSet.java:1503)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.ibatis.logging.jdbc.ResultSetLogger.invoke(ResultSetLogger.java:59)
at sun.proxy.$Proxy13.getObject(Unknown Source)
at org.apache.ibatis.type.ObjectTypeHandler.getNullableResult(ObjectTypeHandler.java:34)
at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:51)
at org.apache.ibatis.type.UnknownTypeHandler.getNullableResult(UnknownTypeHandler.java:49)
at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:51)
at org.apache.ibatis.executor.resultset.FastResultSetHandler.getPropertyMappingValue(FastResultSetHandler.java:325)
at org.apache.ibatis.executor.resultset.FastResultSetHandler.applyPropertyMappings(FastResultSetHandler.java:306)
at org.apache.ibatis.executor.resultset.FastResultSetHandler.getRowValue(FastResultSetHandler.java:275)
at org.apache.ibatis.executor.resultset.FastResultSetHandler.handleRowValues(FastResultSetHandler.java:221)
at org.apache.ibatis.executor.resultset.FastResultSetHandler.handleResultSet(FastResultSetHandler.java:193)
at org.apache.ibatis.executor.resultset.FastResultSetHandler.handleResultSets(FastResultSetHandler.java:159)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:57)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:59)
at sun.proxy.$Proxy10.query(Unknown Source)
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:57)
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:259)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:132)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:105)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:62)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:43)
at sun.proxy.$Proxy9.selectById(Unknown Source)
at com.zfy.controller.test.ControllerTest.selectById(ControllerTest.java:267)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.ClassNotFoundException: oracle.xml.binxml.BinXMLException
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 67 more

1个回答

lyyybz
lyyybz   Rxr 2016.08.19 10:53

请问你的问题解决了么,我碰到和你一样的问题!

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!