0

在运行以下代码段

String hqlCount = "select count(*) from person";
int count = (Integer)sess.createQuery(hqlCount).uniqueResult();

我得到了这个例外

org.hibernate.hql.ast.QuerySyntaxException: person is not mapped [select count(*) from person]

org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)
org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)
org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:255)
org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
org.hibernate.engine.query.HQLQueryPlan.<init>(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:1623)
servlets.InsertPerson.doPost(InsertPerson.java:43)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

我已经通过创建名为的休眠映射文件将person类映射到表并将此标记添加到休眠配置文件personperson.hbm.xml<mapping resource="person.hbm.xml"/>

4

1 回答 1

0

异常指出 - 表person未映射到任何实体类。

请为表创建映射(使用@Entity

@Entity
@Table(name='person')
class Person {


}
于 2013-06-28T06:29:17.747 回答