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
推荐阅读
-
1548-Cannot load from mysql.proc.The table is probably corru_MySQL
-
UCenter info: MySQL Query Error SQL:SELECT value FROM [Table]vars WHERE noteexists
-
UCenter info: MySQL Query Error SQL:SELECT value FROM [Table]vars WHERE noteexists
-
mysql中错误:1093-You can’t specify target table for update in FROM clause的解决方法
-
delete from 表名与truncate table 表名区别
-
mysql中错误:1093-You can’t specify target table for update in FROM clause的解决方法
-
delete from 表名与truncate table 表名区别
-
UCenter info: MySQL Query Error SQL:SELECT value FROM [Table]vars WHERE noteexis
-
mssql server 存储过程里,bulk insert table from '路径+文件',路径固定,文件名不固定的实现方法
-
Error: cannot fetch last explain plan from PLAN_TABLE