gpt4 book ai didi

java - org.hibernate.hql.ast.QuerySyntaxException 与 Hibernate

转载 作者:搜寻专家 更新时间:2023-10-30 21:04:37 25 4
gpt4 key购买 nike

我不熟悉将 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 {
.....

谢谢,

最佳答案

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

<?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,我没有做更多的事情,所以我不知道是否有办法添加整个包。据我所知,在使用 hibernate.cfg.xml 时,必须直接指定每个持久类。

关于java - org.hibernate.hql.ast.QuerySyntaxException 与 Hibernate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/854978/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com