NamedQuery 未找到 Hibernate4 Seam 2.2 JPA 2.0 和 Jboss eap 6

NamedQuery not found Hibernate4 Seam 2.2 JPA 2.0 and Jboss eap 6

我在 JBOSS EAP 6.3 服务器上收到未找到命名查询的错误消息。我在我的应用程序中使用 Hibernate4 Seam 2.2 JPA 2.0 和 Jboss eap 6。

Caused by: java.lang.IllegalArgumentException: Named query not found: findOfficerByEmpIDFetchAssigners
at org.hibernate.ejb.AbstractEntityManagerImpl.createNamedQuery(AbstractEntityManagerImpl.java:601) [hibernate-entitymanager-4.2.14.SP1-redhat-1.jar:4.2.14.SP1-redhat-1]
at org.jboss.seam.persistence.EntityManagerProxy.createNamedQuery(EntityManagerProxy.java:46) [jboss-seam-2.2.0.GA.jar:2.2.0.GA]
at com.wachovia.apps.amaster.BatchProcessorBean.getLoggedInUser(BatchProcessorBean.java:68) [amaster-ejb-1.0.jar:]

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence 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_2_0.xsd" 
         version="2.0">

   <persistence-unit name="AccountMaster">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:jboss/datasources/jdbc/AccountMaster</jta-data-source>
  <properties>
     <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
     <property name="hibernate.cache.use_query_cache" value="false"/>
     <property name="hibernate.show_sql" value="false"/>
     <property name="jboss.entity.manager.jndi.name" value="java:jboss/AmasterEntityManager"/>
     <property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/AmasterEntityManagerFactory"/> 
     <property name="hibernate.default_schema" value="AMASTER"/>
     <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
     <property name="hibernate.id.new_generator_mappings" value="false"/> 
     <property name="jboss.as.jpa.managed" value="false"/>         
     <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
     <property name="jboss.as.jpa.adapterModule" value="org.jboss.as.jpa.hibernate:4"/>
     <property name="jboss.as.jpa.adapterClass" value="org.jboss.as.jpa.hibernate4.HibernatePersistenceProviderAdaptor"/>      
  </properties>


我的实体 class,

@Entity
@Table(name="OFFICER")
@NamedQueries({ 
@NamedQuery(name="findOfficerByEmployeeId", 
            query="from Officer where upper(employeeId)=upper(:id) order by employeeId"),
@NamedQuery(name="findOfficerByEmpIDFetchAssigners", 
            query="from Officer o left join fetch o.assigners ass where upper(o.employeeId) = :id")     
})
public class Officer  implements java.io.Serializable {

这是我的无状态 bean class 我正在调用 NamedQuery,

@Stateless
@Name("batchProcessor")
@AutoCreate
@TransactionManagement(TransactionManagementType.BEAN)
public class BatchProcessorBean implements BatchProcessor, Serializable {
private static final long serialVersionUID = 395715959808111918L;

@SuppressWarnings("seam-unresolved-variable")
@In(value = "entityManager")
private EntityManager em;

public Officer getLoggedInUser(String employeeID) {
    UserTransaction instance = Transaction.instance();
    List<Officer> list = em.createNamedQuery("findOfficerByEmpIDFetchAssigners").setParameter("id", employeeID).getResultList();

我将 persistence.xml 放在 ejb/resources/META-INF 文件夹下。 我已经尝试过之前关于 NamedQuery Not found 问题的帖子。这并没有解决我的问题

请帮我解决这个问题。谢谢

我已经解决了这个问题。我在 persistence.xml 中添加了以下 class 标签来解决问题,

<class>com.wachovia.apps.amaster.orm.Officer</class>

标签的顺序在 persistence.xml 中很重要。在我的例子中,这个 class 标签必须添加在 <properties> 标签之前和 <jta-data-source> 标签之后。