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

org.hibernate.hql.internal.ast.QuerySyntaxException: agency is not mapped

程序员文章站 2022-07-12 16:10:47
...

今天在使用hibernate+springmvc框架,做一个查询时出现了一个错误,sql语句大体为:

select count(id) from address where agency_id in (select id from agency where pids like '%,42,' or id=42) and shflag=0 order by id desc

在mysql查询中能够正常运行,在控制台中报错

java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: agency is not mapped [select c from com.demi.cms.model.Address c where agency_id in (select id from agency where pids like '%,42,' or id=42) and shflag=0 order by id desc] at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert AbstractEntityManagerImpl.java:1750) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1683) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:331) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source)~~~~~~

 

提示我们是查询语法错误,后来仔细一想hibernate对大小写敏感,将语句重新更改了一下:

select count(id) from Address where agency_id in (select id from Agency where pids like '%,42,' or id=42) and shflag=0 order by id desc,问题解决!