2016-01-26 108 views
0

我收到JBOSS EAP 6.3服務器上的命名查詢未發現錯誤消息。我在我的應用程序中使用Hibernate4 Seam 2.2 JPA 2.0和Jboss eap 6。NamedQuery未找到Hibernate4煤層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> 


我的實體類,

@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類我打電話了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 /資源/ META-INF文件夾。 我已經嘗試了關於NamedQuery未找到問題的以前的帖子。那不是我修的問題

請幫我找出這個問題。由於

回答

0

我已經解決了這個問題。我已經添加了下面的類標籤persistence.xml中解決這個問題,

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

標記的順序是在persistence.xml中很重要的。在我而言,這個類標籤必須在<properties>標記之前和<jta-data-source>標籤後加入。