JPA本地查询返回类型与期望类型不符

笔墨Beam 上海海鼎 Java工程师  2015-10-30 04:24:52
源代码如下
StringBuffer sql = new StringBuffer();
sql.append(" SELECT withdraw.realname, user.username, user.mobile, withdraw.withdraw_money," +
" withdraw.advance_money, withdraw.application_time, withdraw.status" +
" FROM wm_user_withdraw AS withdraw" +
" JOIN wm_user_users AS user ON withdraw.user_id = user.id" +
" WHERE 1 = 1");

Integer status = (Integer) filters.get("status");
if (status != null) {
sql.append(" AND withdraw.status = " + status);
}

String realname = (String) filters.get("realname");
if (StringUtils.isNotEmpty(realname)) {
sql.append(" AND withdraw.realname = " + realname);
}

String mobile = (String) filters.get("mobile");
if (StringUtils.isNotEmpty(mobile)) {
sql.append(" AND user.mobile = " + mobile);
}

String username = (String) filters.get("username");
if (StringUtils.isNotEmpty(username)) {
sql.append(" AND user.username = " + username);
}

Long applicationTimeStart = (Long) filters.get("applicationTimeStart");
if (applicationTimeStart != null) {
sql.append(" AND withdraw.application_time >= " + applicationTimeStart);
}

Long applicationTimeEnd = (Long) filters.get("applicationTimeEnd");
if (applicationTimeEnd != null) {
sql.append(" AND withdraw.application_time < " + applicationTimeEnd);
}
sql.append(" ORDER BY withdraw.application_time DESC");

Query query = manager.createNativeQuery(sql.toString());
if (query == null || query.getResultList() == null || query.getResultList().isEmpty()) {
return new ArrayList<Object[]>();
}
return query.getResultList();

SQL经过拼接之后如下
 SELECT withdraw.realname AS rname, user.username AS username, user.mobile AS usermobile, withdraw.withdraw_money AS usermoney, withdraw.advance_money AS advmoney, withdraw.application_time AS atime, withdraw.status AS wstt FROM wm_user_withdraw AS withdraw JOIN wm_user_users AS user ON withdraw.user_id = user.id WHERE 1 = 1 ORDER BY withdraw.application_time DESC

在navicat中测试也正常,程序使用中报错,跟断点发现最后的status返回的是boolean类型,


但我期望的是int或者byte类型,数据库存的时0、1、2、3、4、5等。求问怎么变为期望的int或byte类型
...全文
172 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
笔墨Beam 2015-11-04
原因:mysql设置字段为tinyint时,返回类型自动为boolean类型 解决方案:讲tinyint变为int,就会返回为integer类型
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2015-10-30 04:24
社区公告
暂无公告