正在做一个WEB项目,用Struts+Hibernate实现(很小的一个项目),现在有一些问题需要高手帮忙解决一下,详见内容
当我“从数据库中按照2个字段为条件查找记录的时候”,异常如下:
22:19:00,921 DEBUG ErrorCounter:68 - throwQueryException() : no errors
22:19:01,125 DEBUG HqlSqlBaseWalker:111 - select < < begin [level=1, statement=select]
Exception in thread "main " org.hibernate.hql.ast.QuerySyntaxException: cart_user is not mapped [from cart_user c where c.name=:userName and c.password=:password]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:257)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan. <init> (HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan. <init> (HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at com.lq.shoppingcart.biz.UserBiz.login(UserBiz.java:22)
at com.lq.shoppingcart.biz.TestCha.main(TestCha.java:10)
其中:Exception in thread "main " org.hibernate.hql.ast.QuerySyntaxException: cart_user is not mapped [from cart_user c where c.name=:userName and c.password=:password]
这一句是什么意思?按照字面意思理解的话说“表(cart_user)没有映射(mappde),可是我这些表已经做好了映射关系,而且对象的持久化没有问题呀,难道我的HQL语句有问题?如果把Hibernate换成JDBC的话,再进行查找,就没有问题,这是怎么回事呀?
[解决办法]
from User ...........
hql 要写类名 不是表名