Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java org.hibernate.hql.internal.ast.QuerySyntaxException_Java_Jpa_Ejb_Wildfly - Fatal编程技术网

Java org.hibernate.hql.internal.ast.QuerySyntaxException

Java org.hibernate.hql.internal.ast.QuerySyntaxException,java,jpa,ejb,wildfly,Java,Jpa,Ejb,Wildfly,我得到这个错误: Caused by: javax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: TblEmployee is not mapped [FROM TblEmployee] Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: TblE

我得到这个错误:

Caused by: javax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: TblEmployee is not mapped [FROM TblEmployee]
    Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: TblEmployee` is not mapped
我研究过互联网,它说我没有使用类名,而是使用表名。我确保我做得正确。我正在尝试连接到sql server数据库

JPA:

ejbpackage

com.ray.adtf.ejb;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import com.ray.adtf.jpa.TblEmployee;
import java.util.List;

@Stateless
public class GridMasterBean {

    @PersistenceContext
    private EntityManager em;

        public List<TblEmployee> getDisplayGridList() {
            return em.createQuery("select t FROM TblEmployee t", TblEmployee.class).getResultList();

    }
com.ray.adtf.ejb;
导入javax.ejb.Stateless;
导入javax.persistence.EntityManager;
导入javax.persistence.PersistenceContext;
导入com.ray.adtf.jpa.TblEmployee;
导入java.util.List;
@无国籍
公共类GridMasterBean{
@持久上下文
私人实体管理者;
公共列表getDisplayGridList(){
返回em.createQuery(“从TblEmployee t中选择t”,TblEmployee.class).getResultList();
}
persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
 <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
 <persistence-unit name="Test-Persistence" transaction-type="RESOURCE_LOCAL">
 <jta-data-source>java:/ProgramHierarchy</jta-data-source>
 <class>com.ray.adtf.jpa.TblEmployee</class>
 <class>com.ray.adtf.jpa.TblProgram</class>
 <exclude-unlisted-classes>false</exclude-unlisted-classes>
 </persistence-unit>
 </persistence>

java:/ProgramHierarchy
com.ray.adtf.jpa.TblEmployee
com.ray.adtf.jpa.TblProgram
假的

我做错了什么?

您将HQL与JPA类混合在一起

EntityManager
来自JPA。JPA的查询要求您使用JPQL(JPA查询语言),就像实体中准备好的查询一样(
SELECT t from TblEmployee t

现在,TblEmployee中的
是HQL(Hibernate查询语言),当您不使用Hibernate作为JPA提供程序时,应该直接使用它(使用Hibernate类,例如
会话

简言之:

如果要包括从
java.persistence
导入的内容,请不要添加从
org.hibernate
导入的内容并使用JPQL(以
开始选择

如果您直接使用Hibernate,请不要使用JPA类,如
EntityManager
和相关类。不过,您似乎可以在Hibernate查询中使用JPQL或HQL

一些人认为食物:


您尚未在persistence.xml配置文件中声明实体类:

<property name="hibernate.archive.autodetection" value="class, hbm"/>


这不是您发现的问题,但当使用Hibernate(或JPA或其他ORM)时,我建议停止使用DB概念(例如
TblEmployee
中的
Tbl
)当您同时声明
事务类型
事务和
jta数据源
时,persistence.xml中存在不一致性。我假设您想要使用jta事务,因此
事务类型=“RESOURCE\u LOCAL”
不是必需的。谢谢,所以我修改了我的ejb以返回em.createQuery(“从TblEmployee t中选择t”,TblEmployee.class).getResultList();我也删除了对HQL的所有引用,但出现了相同的错误。这些链接很有用,但我无法解决我的问题,因为桌面应用程序(没有EJB,只有JPA)运行得很好(如果您想检查差异,我可以提供一个链接).对于WildFly,
事务类型
通常是JTA,或者您必须进行额外的配置()。但是如果是这个问题,我希望抛出不同的异常。
<property name="hibernate.archive.autodetection" value="class, hbm"/>