一尘不染

带有Hibernate的org.hibernate.hql.ast.QuerySyntaxException

hibernate

我是初次使用Hibernate和Java。我收到以下异常。我在网上找到的有关此错误的信息似乎没有帮助。有任何想法吗?例外:

java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException:

ApplPerfStats is not mapped [select count(c) from ApplPerfStats c]
    at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:601)
    at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:96)
    at com.icesoft.icefaces.samples.datatable.jpa.CustomerDAO.findTotalNumberCustomers(CustomerDAO.java:89)
    at com.icesoft.icefaces.samples.datatable.ui.SessionBean.getDataPage(SessionBean.java:189)
    at com.icesoft.icefaces.samples.datatable.ui.SessionBean.access$0(SessionBean.java:185)
    at com.icesoft.icefaces.samples.datatable.ui.SessionBean$LocalDataModel.fetchPage(SessionBean.java:245)
    at com.icesoft.icefaces.samples.datatable.ui.PagedListDataModel.getPage(PagedListDataModel.java:121)
    at com.icesoft.icefaces.samples.datatable.ui.PagedListDataModel.getRowCount(PagedListDataModel.java:100)
    at com.icesoft.faces.component.datapaginator.DataPaginator.isModelResultSet(DataPaginator.java:1091)
    at com.icesoft.faces.component.datapaginator.DataPaginatorRenderer.encodeBegin(DataPaginatorRenderer.java:201)

被称为的地方:

@SuppressWarnings("unchecked")
public Long findTotalNumberCustomers() {
    EntityManagerHelper.log("finding number of Customer instances", Level.INFO, null);
    try {
        String queryString = "select count(c) from ApplPerfStats c";
        return (Long) getEntityManager().createQuery(queryString).getSingleResult();
    } catch (RuntimeException re) {
        EntityManagerHelper.log("find number of Appl_perf_stats failed",
                Level.SEVERE, re);
        throw re;
    }
}

映射到数据库表的类:

package com.icesoft.icefaces.samples.datatable.jpa;

import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "Appl_perf_stats", uniqueConstraints = {})
public class ApplPerfStats implements java.io.Serializable {
.....

谢谢,


阅读 280

收藏
2020-06-20

共1个答案

一尘不染

尝试在文件中的class下添加元素。persistence-unit``persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence ...>

    <persistence-unit name="unit">
        <class>com.icesoft.icefaces.samples.datatable.jpa.ApplPerfStats</class>
        ...
     </persistence-unit>
<persistence>

我在JPA /
EntityManager上所做的工作还不止这些,所以我不知道是否有添加整个程序包的方法。AFAIK在使用时hibernate.cfg.xml,必须直接指定每个持久类。

2020-06-20