解決Hibernate使用HQL查詢出現is not mapped問題
環境:Hibernate 5.1.0.Final,IntelliJ IDEA 2016.2.2
檢查實體Bean配置一切正常,檢查對映配置檔案和hibernate.cfg.xml配置檔案也是正常的。
通過搜尋都說是HQL查詢根據的是實體名而不是表名查詢的,那個我也是對的,實在想不通會出現is not mapped問題。異常資訊如下:
Exception in thread "main" org.hibernate.hql.internal.ast.QuerySyntaxException: UsersEntity is not mapped [FROM UsersEntity ]
at org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:79 )
at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:218)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:142)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:115 )
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:76)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:150)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:302)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:240 )
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1907)
at TestHibernate.main(TestHibernate.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: UsersEntity is not mapped
at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:171)
at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:91)
at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:79)
at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:321)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3704)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3593)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:718)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:574)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:311)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:259)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:262)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:190)
... 13 more
最後仔細排查才發現是被IDE給坑了。。
我是通過IDEA自動生成的Session工廠類和對映配置檔案,問題就出在IDE自動生成的那個獲取Session的工廠類上。以下是IDE自動生成類的完整內容:
public class Main {
private static final SessionFactory ourSessionFactory;
private static final ServiceRegistry serviceRegistry;
static {
try {
Configuration configuration = new Configuration();
configuration.configure();
serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
ourSessionFactory = configuration.buildSessionFactory(serviceRegistry);
} catch (Throwable ex) {
throw new ExceptionInInitializerError(ex);
}
}
public static Session getSession() throws HibernateException {
return ourSessionFactory.openSession();
}
/*
public static void main(final String[] args) throws Exception {
final Session session = getSession();
try {
System.out.println("querying all the managed entities...");
final Map metadataMap = session.getSessionFactory().getAllClassMetadata();
for (Object key : metadataMap.keySet()) {
final ClassMetadata classMetadata = (ClassMetadata) metadataMap.get(key);
final String entityName = classMetadata.getEntityName();
final Query query = session.createQuery("from " + entityName);
System.out.println("executing: " + query.getQueryString());
for (Object o : query.list()) {
System.out.println(" " + o);
}
}
} finally {
session.close();
}
} */
}
我只是簡單的將main方法註釋掉了,其實問題就是出在serviceRegistry上面的,只要移除掉這個就好了。
修改後為:
public class Main {
private static final SessionFactory ourSessionFactory;
static {
try {
Configuration configuration = new Configuration();
configuration.configure();
ourSessionFactory = configuration.buildSessionFactory();
} catch (Throwable ex) {
throw new ExceptionInInitializerError(ex);
}
}
public static Session getSession() throws HibernateException {
return ourSessionFactory.openSession();
}
}
因為才剛開始學,具體的原因還沒有進行分析,以後有時間再慢慢查詢資料閱讀原始碼分析吧。
相關推薦
解決Hibernate使用HQL查詢出現is not mapped問題
環境:Hibernate 5.1.0.Final,IntelliJ IDEA 2016.2.2 檢查實體Bean配置一切正常,檢查對映配置檔案和hibernate.cfg.xml配置檔案也是正常的。 通過搜尋都說是HQL查詢根據的是實體名而不是表名查詢的,那
hibernate 出現***is not mapped
初學hibernate,建立好專案執行時報錯,重新修改配置之類的都不行,最後找到問題原因是作HQL查詢時候from 後應該是表對映的對應實體類名稱,而不是資料庫中的表名稱。 查詢的文章:http://blog.csdn.net/jsj_126abc/article/deta
SSH框架中hibernate 出現 user is not mapped 問題
eat and lis pub dao col 自己 return alc SSH框架中hibernate 出現 user is not mapped 問題 在做SSH框架整合時,在進行DAO操作時。這裏就只調用了chekUser()方法。運行時報 us
Hibernate 中出現 users is not mapped 問題
hibernate.cfg.xml中: 原始碼: <hibernate-mapping auto-import="false" default-access="field" default-lazy="false"> <class name="pojo.User" t
安裝.whl檔案出現 is not a supported wheel on this platform.解決辦法
有一次在學習機器學習演算法的時候,要安裝一個scikit-learn庫,需要依賴庫numpy和matplot庫,但是我安裝的時候出現了is not a supported wheel on this platform的錯誤,我先百度了一下嘗試一些方法: 1. 在pytho
Android N載入系統私有庫時出現is not accessible for the namespace錯誤和針對該錯誤的解決方法
谷歌從Android N開始,除了那些在Android NDK提供的庫之外,限制了應用對系統私有庫的載入。既然是限制了,想通過以前的方法去載入庫已經行不通了。所以目前的解決方法就是把應用需要載入的庫和需要依賴的庫從系統中pull出來,然後整合到自己的應用當中。本文是看了這篇
Hibernate或者ssh三大框架中出現 XXXX is not mapped問題
錯誤異常資訊: org.springframework.orm.hibernate3.HibernateQueryException: loginUser is not mapped [from loginUser order by userId]; nested exception is org.hibe
Hibernate 中出現表名(XXX) is not mapped 問題
hibernate.cfg.xml:<mapping resource="com/lian/bean/User.hbm.xml" />在網上找了很多,但還是不給力,大家都沒提些有建設性的解決方案,基本上都是說配置有問題。不過自己感覺是這個出問題:String sql = "select u.pas
org.hibernate.hql.internal.ast.QuerySyntaxException: USER is not mapped 報錯解決
錯誤日誌: org.hibernate.hql.internal.ast.QuerySyntaxException: USER is not mapped [FROM USER] at org.hibernate.hql.internal.ast.QuerySyntaxEx
Hibernate查詢報錯:org.hibernate.hql.internal.ast.QuerySyntaxException: XXX is not mapped
這個錯誤的產生原因是,hibernate執行查詢的語句hql是面向物件的查詢,而不是面向資料庫表的查詢,因此在hql語句中的物件名必須與實體類的類名一致,嚴格區分大小寫。 如實體類為 Car,則hql
錯誤筆記之Hibernate出現xxx is not mapped[from Xxx where ...]的原因排查
將自己在部落格園的部落格轉移過來1.檢查自己寫的hql語句是否使用了資料庫的表名而不是實體類的類名,比如資料庫表為user_tb,而對應的pojo類為UserTb,hql是"from user_tb where xx=xx",如果是這樣,將user_tb改為UserTb就可以了。有條件的話也是一樣的,請使用類
is not mapped 錯誤改正
figure open action void pen ble lai ordinary intra 我出現的錯誤是:oorg.hibernate.hql.ast.QuerySyntaxException: DEPT is not mapped [from DEPT] 配置
SSH執行hql報錯:Caused by: org.hibernate.hql.ast.QuerySyntaxException: user is not mapped [from user where username = ?]
執行 occurred ble xml文件 ron red 報錯 temp caused 報錯信息: ERROR Dispatcher:38 - Exception occurred during processing request: user is not mapped
SpringData : xxx_xxx is not mapped
trac HERE 進行 mapped 最好的 實現 cep exception inter 今天寫一個查詢語句的時候,報錯如下 org.springframework.beans.factory.BeanCreationException: Error crea
tb_Countries_Name is not mapped [from tb_Countries_Name where Id = '1' ]
在專案的資料庫建立表的時候,遵循了建表的規則:tb_***_**,然而hibernate在對映的時候系統自動把下劃線_給去掉了直接變為:TbXXX,在Javabean裡做hql查詢的時候沒有注意,寫的是資料庫名:from tb_***_***,導致出現tb_Countries_Name is n
解決:Uncaught ReferenceError: jQuery is not defined
在我寫好後臺程式碼準備在登陸頁面登陸的時候發現的錯誤,但是我報錯相關的js檔案都正確匯入了的 百度了後,參照如下貼子: https://www.aliyun.com/jiaocheng/984428.html 其中說到:頁面jQuery.js的引用位置問題,如果匯入了其它與jque
解決Ubuntu下出現“TeamViewer: Not ready. Check your connection”的問題
解決方法: 重啟TeamViewer 服務: sudo teamviewer daemon stop sudo teamviewer daemon start 當然你也可以使用該命令來重啟它: sudo teamviewer daemon restart 再檢查是否重啟成功
org.hibernate.hql.internal.ast.QuerySyntaxException: Base is not mapped [from Base]
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Base is not mapped org.hibernate.hql.internal.ast.QuerySyntaxException: Base is not
openstack報錯:Host is not mapped to any cell
環境說明: openstack版本 pike 控制節點主機 openstack-controller(ubuntu 16.04.5) 計算節點主機 openstack-computer(ubuntu 16.0
jpa @query註解使用時的 xxx is not mapped
@Modifying @Query(value = "UPDATE MANUAL_FILE SET FILE_INFO = ?2 , USER_ID = ?3 WHERE ID = ?1 ", nativeQuery = true) void updateByI