日期:2014-05-17  浏览次数:20778 次

请问这样的hibernate语句出现了什么问题
我的方法是如下的:

//根据要求提取教师的信息
public List<Teacher> searchTeacher(String college,String department, String postion, String education,String teacherId) {

Configuration cfg=new Configuration().configure();
SessionFactory sf=cfg.buildSessionFactory();
Session s=sf.openSession();
String hql="from Teacher a t where t.college=:c and t.department=:d and t.postion=:p and" +
" t.education=:e and t.teacherId=:t";
Transaction tx=s.beginTransaction();
Query query=s.createQuery(hql);
query.setString("c", college); 
query.setString("d", department);
query.setString("p", postion);
query.setString("e", education);
query.setString("t", teacherId);
List<Teacher> list=query.list();
tx.commit();
s.close();
return list;

}

但是我运行的时候就出现了这样的错误提示:
Struts Problem Report
Struts has detected an unhandled exception: 

Messages: unexpected token: t near line 1, column 36 [from com.gdpu.project.vo.Teacher a t where t.college=:c and t.department=:d and t.postion=:p and t.education=:e and t.teacherId=:t] 
 
File: org/hibernate/hql/ast/QuerySyntaxException.java 
Line number: 31 


--------------------------------------------

Stacktraces
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: t near line 1, column 36 [from com.gdpu.project.vo.Teacher a t where t.college=:c and t.department=:d and t.postion=:p and t.education=:e and t.teacherId=:t] 
  org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
  org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
  org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
  org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:261)
  org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:159)
  org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:113)
  org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:77)
  org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:56)
  org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
  org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
  org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
  org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1624)
  com.gdpu.project.dao.impl.TeacherDaoImpl.searchTeacher(TeacherDaoImpl.java:330)
  com.gdpu.project.service.impl.ChengGuoServiceImpl.searchCgProjectByDate(ChengGuoServiceImpl.java:400)
  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)
  org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
  org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
  org.springframework.aop.framework.ReflectiveMethodInvocation.