且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

HQL 查询中的 Hibernate 表未映射错误

更新时间:2022-02-24 08:58:50

异常信息说:

图书未映射 [SELECT COUNT(*) FROM Books];嵌套异常是 org.hibernate.hql.ast.QuerySyntaxException:书籍未映射 [SELECT COUNT(*) FROM Books]

Books 未映射.也就是说,没有名为 Books 的映射类型.

Books is not mapped. That is, that there is no mapped type called Books.

事实上,没有.您的映射类型称为 Book.它映射到名为Books 的表,但类型称为Book.当您编写 HQL(或 JPQL)查询时,您使用类型的名称,而不是表.

And indeed, there isn't. Your mapped type is called Book. It's mapped to a table called Books, but the type is called Book. When you write HQL (or JPQL) queries, you use the names of the types, not the tables.

因此,将您的查询更改为:

So, change your query to:

select count(*) from Book

虽然我认为可能需要

从Book b中选择count(b)

如果 HQL 不支持 * 符号.

If HQL doesn't support the * notation.