org.hibernate.hql.internal.ast.QuerySyntaxException: 【tableName】 is not mapped

你要認真檢查一下你寫的hql語句,一定是對象查詢,特別是【tableName】 不要寫你要查詢的表,而是查詢的對象
比如:
public long getTypeCount(Patent patent) {
String hqlString = “select count(*) from Patent as p where p.type =’”+patent.getType()+"’";
Query query = this.getSession().createQuery(hqlString);
long count =0;
count = ((Number)query.uniqueResult()).intValue();
return count;
}

Patent 是一個對象

而數據庫的表名是patent 如果寫成String hqlString = “select count(*) from patent as p where p.type =’”+patent.getType()+"’";
!!!!!!!切記!!!!!!!!!!!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章