mybatis java.lang.UnsupportedOperationException
mybatis抛出下面的异常:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.lang.UnsupportedOperationException ### The error may exist in file [C:\apache-tomcat-8.0.21\webapps\ems\WEB-INF\classes\config\mappers\UserMapper.xml] ### The error may involve com.ems.mapper.UserMapper.findPermissionsByUserId ### The error occurred while handling results ### SQL: select distinct permission from privilege p inner join user_privilege up on p.id=up.privilege_id inner join user u on u.id=up.user_id where u.id=? ### Cause: java.lang.UnsupportedOperationException
对应的语句如下:
<select id="findPermissionsByUserId" parameterType="java.lang.Integer" resultType="java.util.Set"> select distinct permission from privilege p inner join user_privilege up on p.id=up.privilege_id inner join user u on u.id=up.user_id where u.id=#{userId, jdbcType=INTEGER} </select>
错误原因是 resultType="java.util.Set" ,这里应该改成: resultType="java.lang.String"
这里 resultType 指的是 select 返回的每一条记录 的类型,而不是所有记录组成的类型。