tianzhidao28 / rapid-framework

Automatically exported from code.google.com/p/rapid-framework
0 stars 0 forks source link

Ibatis3 分页查询bug. #44

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
执行带有in条件的分页查询语句,查询count语句时正确找到参�
��。而查询具体数据时
找不到参数。

java代码:

Map<String, Object> filters = new HashMap<String, Object>();

List<Long> adminList = new ArrayList<Long>();
Collection<GrantedAuthority> grants = SecurityContextHolder.getContext
().getAuthentication().getAuthorities();
for(GrantedAuthority grant : grants) {
    GrantedAuthorityInfo g = (GrantedAuthorityInfo)grant;
    adminList.add(g.getAuthorityId());
}
filters.put("parentIds", adminList);
int totalCount = roleDao.pageQueryRoleCount(filters);
Page<Role> page = new Page<Role>(pageRequest, totalCount);

filters = PageUtils.createFilters(page, pageRequest);
filters.put("parentIds", adminList);
List<Role> list = roleDao.pageQueryRole(filters);
page.setResult(list);
return page;

xml:

    <select id="pageQueryRoleCount" resultType="int" 
parameterType="hashmap">
        select count(*) from mf_role where parentId in 
        <foreach item="item" index="index" collection="parentIds" 
open="(" separator="," close=")"> 
            #{item} 
        </foreach>
    </select>

    <select id="pageQueryRole" resultType="Role" 
parameterType="hashmap">
        select * from mf_role where parentId in 
        <foreach item="item" index="index" collection="parentIds" 
open="(" separator="," close=")"> 
            #{item} 
        </foreach>
    </select>

stack :

2010-03-23 15:34:29,921 DEBUG [java.sql.Connection] - <ooo Connection 
Opened>
2010-03-23 15:34:29,984 DEBUG [java.sql.PreparedStatement] - <==>  
Executing: select count(*) from mf_role where parentId in ( ? ) >
2010-03-23 15:34:29,984 DEBUG [java.sql.PreparedStatement] - <==> 
Parameters: -1(Long)>
2010-03-23 15:34:29,984 DEBUG [java.sql.Connection] - <xxx Connection 
Closed>
2010-03-23 15:34:30,046 DEBUG [java.sql.Connection] - <ooo Connection 
Opened>
2010-03-23 15:34:30,046 DEBUG [java.sql.Connection] - <xxx Connection 
Closed>
2010-3-23 15:34:30 org.apache.catalina.core.ApplicationDispatcher invoke
严重: Servlet.service() for servlet starframe threw exception
org.apache.ibatis.type.TypeException: JDBC requires that the JdbcType must 
be specified for all nullable parameters.
    at org.apache.ibatis.type.BaseTypeHandler.setParameter
(BaseTypeHandler.java:14)
    at 
org.apache.ibatis.executor.parameter.DefaultParameterHandler.setParameters
(DefaultParameterHandler.java:73)
    at 
org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize
(PreparedStatementHandler.java:61)
    at 
org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize
(RoutingStatementHandler.java:43)
    at org.apache.ibatis.executor.SimpleExecutor.prepareStatement
(SimpleExecutor.java:56)
    at org.apache.ibatis.executor.SimpleExecutor.doQuery
(SimpleExecutor.java:40)
    at org.apache.ibatis.executor.BaseExecutor.query
(BaseExecutor.java:90)
    at org.apache.ibatis.executor.CachingExecutor.query
(CachingExecutor.java:68)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)

Original issue reported on code.google.com by libinson...@gmail.com on 23 Mar 2010 at 7:39

GoogleCodeExporter commented 9 years ago
这个不是分页的问题,是你的#{item} 需要指定类型。
如 #{item,jdbcType=VARCHAR}

好像是这样, 
你自己试一下,就算没有分页,这个sql在iBatis中也是错误的.

org.apache.ibatis.type.TypeException: JDBC requires that the JdbcType must 
be specified for all nullable parameters.

Original comment by bad...@gmail.com on 23 Mar 2010 at 8:08