遇到个bug,数据库时间存储用了datetime,但是下面的java jpa代码,查询回来,却只有日期。
String innerSql = getInnerQuery(departmentId, keyword, type, startDate, endDate); SQLQuery query = manager.createNativeQuery(innerSql).unwrap(SQLQuery.class);
if (PublicUtils.isNotEmpty(departmentId)) {
query.setParameter("departmentId", departmentId);
}
if (StringUtils.isNotEmpty(type)) {
query.setParameter("typeParam", Integer.valueOf(type));
}
if (StringUtils.isNotEmpty(keyword)) {
query.setParameter("keyword", keyword);
}
if (startDate != null && endDate != null) {
query.setParameter("startDate", startDate);
query.setParameter("endDate", endDate);
}
query.addScalar("noticeId", StandardBasicTypes.STRING);
query.addScalar("title", StandardBasicTypes.STRING);
query.addScalar("type", StandardBasicTypes.INTEGER);
query.addScalar("createUserId", StandardBasicTypes.STRING);
query.addScalar("createTime", StandardBasicTypes.TIMESTAMP);
query.addScalar("departmentId", StandardBasicTypes.STRING);
query.addScalar("userId", StandardBasicTypes.STRING); query.setResultTransformer(new MyBasicTransformerAdapter()); query.setFirstResult(startIndex);
query.setMaxResults(pageSize);
List<NoticePageListVO> items = query.list();
中的
query.addScalar("createTime", StandardBasicTypes.DATE); 这边要改成
query.addScalar("createTime", StandardBasicTypes.TIMESTAMP);
注意:改成TIME也不行,一定要是TIMESTAMP