标签:dao polardb 问题 mybatis 迁移 com byte ###
环境
polardb版本
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>polardb-jdbc18</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${lib.dir}/polardb-jdbc18.jar</systemPath>
</dependency>
mybatis版本
直接使用springboot引入
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.4</version>
</dependency>
问题描述
javax.servlet.ServletException: org.springframework.dao.DataIntegrityViolationException:
### The error may exist in com/xx/templatedef/dao/oracle/XXTemplateDef_SqlMap.xml
### The error may involve com.xx.templatedef.dao.XXTemplateDefDao.selectTemplateDefByCategoryAndState-Inline
### The error occurred while setting parameters
### SQL: select * from act_xx_tem_def where category=? and deploy_state=1
### Cause: com.aliyun.polardb.util.PSQLException: 不良的类型值 long :
com.aliyun.polardb.util.PSQLException: canot convert the column of type BYTEA to requested type long;
原因
mybatis查询act_tem_def表涉及到blob字段(content_bytes),
默认的BlobTypeHandler的getBlob方法不适用, 需要重写handler
解决方案
-
在业务下重写BlobTypeHandler, 获取getBinaryStream然后转换byte数组
-
mapper.xml -> resultmap中, 加入下述转换
<result column="CONTENT_BYTES" property="contentBytes" jdbcType="BLOB" typeHandler="com.example.springbootpolardb.handler.PolarDbBlobTypeHandler"/>
-
转换逻辑
public static byte[] toByteArray(InputStream input) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int n = 0; while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); } return output.toByteArray(); }
代码
标签:dao,polardb,问题,mybatis,迁移,com,byte,### 来源: https://www.cnblogs.com/qq347061329/p/14781568.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。