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

Today, when using the hibernate+springmvc framework, an error occurred when making a query. The sql statement is roughly as follows:

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

It can run normally in mysql query, and it reports an error in the console

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)~~~~~~

 

It prompted us that the query syntax was wrong. Later, after thinking about the case sensitivity of hibernate, I changed the statement again:

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,问题解决!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326295762&siteId=291194637