ssh框架,hibernate查询报错:
org.hibernate.QueryException: Expected positional parameter count: 2, actual parameters: [] [SELECT * from Ad where projectId = ? and aprojectYear = ?]
大概意思:
org.hibernate.queryexception:预期位置参数计数:2,实际参数:[projectId 和 ProjectYear]
参数个数位置比配!!!
源代码:
public Map<String, List<AttachmentEntity>> loadAttachMapByProjectIdAndProYear(<span style="color:#ff0000;">String projectId,int projectYear</span>) {
List<AttachTypeEntity> attachTypes=getHibernateTemplate().find("FROM AttachTypeEntity WHERE enabled=1 ORDER BY orderNum");
if (attachTypes!=null){
List<AttachmentEntity> attachments=getHibernateTemplate().find(<span style="color:#ff0000;">"FROM AttachmentEntity " +
"WHERE proId=? and proYear=? ORDER BY attachType.orderNum,uploadTime",projectId</span>);
Map<String,List<AttachmentEntity>> map=new HashMap<String, List<AttachmentEntity>>();
if (attachments.size()>0) {
for (AttachTypeEntity attachType : attachTypes) {
List<AttachmentEntity> typedAttachments = new ArrayList<AttachmentEntity>();
for (AttachmentEntity attachment : attachments) {
if (attachment.getAttachType().equals(attachType)) {
typedAttachments.add(attachment);
}
}
map.put(attachType.getTypeId(), typedAttachments);
}
}
return map;
}
return null;
}
改为:
public Map<String, List<AttachmentEntity>> loadAttachMapByProjectIdAndProYear(String projectId,int projectYear) {
List<AttachTypeEntity> attachTypes=getHibernateTemplate().find("FROM AttachTypeEntity WHERE enabled=1 ORDER BY orderNum");
if (attachTypes!=null){
List<AttachmentEntity> attachments=getHibernateTemplate().find("<span style="color:#ff0000;">FROM AttachmentEntity " +
"WHERE proId=? and proYear=? ORDER BY attachType.orderNum,uploadTime",projectId</span>);
Map<String,List<AttachmentEntity>> map=new HashMap<String, List<AttachmentEntity>>();
if (attachments.size()>0) {
for (AttachTypeEntity attachType : attachTypes) {
List<AttachmentEntity> typedAttachments = new ArrayList<AttachmentEntity>();
for (AttachmentEntity attachment : attachments) {
if (attachment.getAttachType().equals(attachType)) {
typedAttachments.add(attachment);
}
}
map.put(attachType.getTypeId(), typedAttachments);
}
}
return map;
}
return null;
}