当前位置: 代码迷 >> Java相关 >> Myeclipse 中的节点有关问题
  详细解决方案

Myeclipse 中的节点有关问题

热度:10648   发布时间:2013-02-25 21:44:18
Myeclipse 中的节点问题
原本流程都没错,一涉及到条件查询就报这个错误。
org.springframework.orm.hibernate3.HibernateQueryException: unexpected AST node: + near line 1, column 34 [from com.pojo.Student where id = +id]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: + near line 1, column 34 [from com.pojo.Student where id = +id]
org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:660)
org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:912)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:904)
com.dao.impl.StudentDaoImpl.queryStudentId(StudentDaoImpl.java:26)
com.service.impl.StudentServiceImpl.queryStudentId(StudentServiceImpl.java:32)
com.action.StudentAction.queryStudentId(StudentAction.java:28)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)


可能是hql语句写错了。但是我看不出来啊。
public Student queryStudentId(Integer id) {
Student student = new Student();
List list = this.getHibernateTemplate().find("from Student where id = +id");
Iterator it = list.iterator();
while(it.hasNext()){
student = (Student)it.next();
}
return student;
}

求高手解答。

------解决方案--------------------------------------------------------
+id什么东西,不应该是具体的id值么?
比如from Student where id = 11
------解决方案--------------------------------------------------------
List list = this.getHibernateTemplate().find("from Student where id = ?").setParameter(0, id);
  相关解决方案