sprint3 +strtus2.0 同样的action调用服务类的方法,参数相同,获取数据query.setParameter会报错.请高手指导一下.
下面调用没有报错.
@Service @Transactional public class NoticeMessageManger 业务类中的一个文件.调用
isReadMessage 方法是NoticeMessageManger类中的一个私有方法.处理集合结果集数据.
getUserReadMessage 服务方法对外提供查询.
上面访问调用执行成功.
/** * FuncName : isReadMessage * Description : 标记用户阅读情况 * @param result * @author: chenhj * @param usercode * @CreateDate 2013-9-4 * @ModifeDate 2013-9-4 */ private String isReadMessage(List<Map<String, Object>> result,String type, String usercode) { if(result==null||result.size()==0)return ""; List<String> ids=new ArrayList<String>(result.size()); for(Map<String, Object> map:result){ ids.add((String)map.get("ID")); } Map<String, Object> param=new HashMap<String, Object>(); param.put("USERCODE", usercode);//查询用户参数 param.put("R_ID", ids);//设置查询参数 param.put("TYPE", type);//类型 param.put("STATUS", "1");//已读状态 List<Map<String, Object>> userReadMessageList=getUserReadMessage(param); int newnum=0; for(Map<String, Object> map:result){ boolean isnew=isNewResut(map,userReadMessageList); if(isnew){ map.put("NEW", "1"); newnum++; }else{ map.put("NEW", "0"); } } return String.valueOf(newnum); }
/** * * FuncName : getUserReadMessage * Description : * @param param KEY: TYPE:关联类型 VALUE: 0:通知公告,1:电子邮件 2:待办工作 3:工作催办 4:一周工作安排<P> * KEY:USERCODE 用户登陆名称 * EKY:STATUS 阅读状态, VALUE:状态:0:没有阅览 1:已经阅览 * EKY:R_ID 业务ID * @return * @author: chenhj * @CreateDate 2013-9-4 * @ModifeDate 2013-9-4 */ public List<Map<String, Object>> getUserReadMessage(Map<String, Object> param){ return userReadMessageDao.getUserReadMessage(param); }
上面getUserReadMessage已经返回没有报错.
下面其它的action中调用服务类同样的方法.就会报错.
在其它的业务实现中调传同样的参数会报错Query 会报参数找不到
error sql:select * from ths_cz.W_USERRELATE t where 1 = 1 and USERCODE =:USERCODE and TYPE =:TYPE and R_ID in(:R_ID ) org.hibernate.QueryParameterException: could not locate named parameter [USERCODE ] at org.hibernate.engine.query.ParameterMetadata.getNamedParameterDescriptor(ParameterMetadata.java:99) at org.hibernate.engine.query.ParameterMetadata.getNamedParameterExpectedType(ParameterMetadata.java:105) at org.hibernate.impl.AbstractQueryImpl.determineType(AbstractQueryImpl.java:437) at org.hibernate.impl.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:407) at com.ths.czproject.dao.UserReadMessageDao.getUserReadMessage(UserReadMessageDao.java:61) at com.ths.czproject.service.NoticeMessageManger.getUserReadMessage(NoticeMessageManger.java:289)
调用的服务类中的getUserReadMessage
/** * * FuncName : showMessage * Description : * @return * @author: chenhj * @CreateDate 2013-9-5 * @ModifeDate 2013-9-5 */ @Action(value="showMessage") public String showMessage(){ String bizId=request.getParameter("bizId"); String bizType=request.getParameter("bizType"); String usercode=login.getId(); Map<String, Object> param=new HashMap<String, Object>(); param.put("R_ID ", bizId); param.put("USERCODE ", usercode); param.put("TYPE ", bizType); List<Map<String, Object>> userReadList=noticeMessageManger.getUserReadMessage(param); Map<String, Object> userRead=new HashMap<String, Object>(); if(userReadList==null||userReadList.size()==0){ userRead.put("USERCODE", usercode); userRead.put("TYPE", bizType); userRead.put("R_ID", bizId); userRead.put("URID", CommUtil.createPkid()); userRead.put("STATUS", CzConstants.USER_MESSAGE_READ); String update= DateUtil.format(new Date()); userRead.put("UPDATETIME",new Date()); noticeMessageManger.saveUserrelate(userRead); }else{ userRead=userReadList.get(0); userRead.put("STATUS", CzConstants.USER_MESSAGE_READ); //String update= DateUtil.format(new Date()); userRead.put("UPDATETIME",new Date()); noticeMessageManger.updateUserrelate(userRead); } return null; }List<Map<String, Object>> userReadList=noticeMessageManger.getUserReadMessage(param); 这里调用里报错.
UserReadMessageDao
@Repository public class UserReadMessageDao extends BaseDAO { /** * * FuncName : getUserReadMessage * Description : * @param param KEY: TYPE:关联类型 VALUE: 0:通知公告,1:电子邮件 2:待办工作 3:工作催办 4:一周工作安排<P> * KEY:USERCODE 用户登陆名称 * EKY:STATUS 阅读状态, VALUE:状态:0:没有阅览 1:已经阅览 * @return * @author: chenhj * @CreateDate 2013-9-4 * @ModifeDate 2013-9-4 */ public List<Map<String, Object>> getUserReadMessage(Map<String, Object> param){ StringBuffer sql = new StringBuffer(); try { sql.append("select * "); sql.append(" from ").append(DBContent.JDBC_USER_THSCZ).append(".W_USERRELATE t "); sql.append(" where 1 = 1 ").append(" "); for(Entry<String, Object> en:param.entrySet()){ if(en.getValue() instanceof String){ sql.append(" and ").append(en.getKey()).append("=:").append(en.getKey()); }else if(en.getValue() instanceof Collection){ sql.append(" and ").append(en.getKey()).append(" in(:").append(en.getKey()).append(")"); } } Query query=getSession().createSQLQuery(sql.toString()); System.out.println("sql:"+sql.toString()); System.out.println(query.getNamedParameters()); for(Entry<String, Object> en:param.entrySet()){ if(en.getValue() instanceof String){ query.setParameter(en.getKey(), en.getValue().toString()); }else if(en.getValue() instanceof Collection){ query.setParameterList(en.getKey(), (Collection)en.getValue()); } } query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); return query.list(); } catch (Exception e) { System.out.println("error sql:"+sql.toString()); e.printStackTrace(); } return null; } }
query.setParameter(en.getKey(), en.getValue().toString()); 出错是执行这语.我查看了一些两种调用的参数.都是一样的,不知道为什么报错.
使用spring3 HibernateDao
import org.springside.modules.orm.hibernate.HibernateDao;
请高手帮助?
问题解决.
Map<String,Object>param=newHashMap<String,Object>();17 | param.put("R_ID",bizId); |
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。