欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

hibernate table is not mapped [from table]

程序员文章站 2022-04-28 18:32:22
...

使用hibernate、spring框架,进行数据库操作时,出现如下错误:

 Exception in thread "main" org.hibernate.hql.internal.ast.QuerySyntaxException: order is not mapped [from order where orderId=?]
	at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180)
	at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)
	at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:93)
	at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:324)
	at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3420)
	at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3309)
	at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:706)
	at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:562)
	at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299)
	at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247)
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:250)
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:138)
	at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:105)
	at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
	at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
	at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:221)
	at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:199)
	at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1778)
	at dao.impl.OrderDao.getOrderById(OrderDao.java:24)
	at service.impl.OrderItemService.createOrderItem(OrderItemService.java:21)
	at second.testOrder.main(testOrder.java:21)

错误原因:因为在OrderDao.java中使用的是hql语句,所以应该使用实体类名而不是数据库表名。

这个例子中,我将OrderDao.java中的“from order where orderId=?”改为“from Order where orderId=?”后,问题便解决了。

转载于:https://my.oschina.net/u/2329828/blog/403590