2015-09-02 8 views
1
java.lang.IllegalArgumentException: No [EntityType] was found for the key class [] in the Metamodel - please verify that the [Entity] class was referenced in persistence.xml using a specific <class> </class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element. 
    at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.entityEmbeddableManagedTypeNotFound(MetamodelImpl.java:173) 

實體類:否[的EntityType]被發現在元模型的關鍵類[] - 請確認[實體]類是在persistence.xml中引用

@Entity 
@Table(name="temp_param") 
public class ParamConfiguration implements Serializable { 
private static final long serialVersionUID = 1L; 
@Id 
@Column(name = "param_group") 
private String paramGroup; 
public String getParamGroup() { 
    return paramGroup; 
} 
public void setParamGroup(String paramGroup) { 
    this.paramGroup = paramGroup; 
} 

DAO代碼:

CriteriaQuery<ParamConfiguration> cq = entityManager 
       .getCriteriaBuilder() 
       .createQuery(ParamConfiguration.class); 
    final Root<ParamConfiguration> ac = cq.from(ParamConfiguration.class); 
    cq.select(ac); 
    TypedQuery<ParamConfiguration> tq=entityManager.createQuery(cq); 
    List<ParamConfiguration> AClist=tq.getResultList(); 

持久化XML:

<persistence-unit name="serCoupons_Cdm" transaction-type="RESOURCE_LOCAL"> 
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> 
    <non-jta-data-source>java:/comp/env/jdbc/CDM</non-jta-data-source> 


    <class>net.odcorp.sas.mrm.beans.AffinityConfiguration</class> 
    <exclude-unlisted-classes>true</exclude-unlisted-classes> 

任何人都可以幫助我......這是@entity類必須具有數據庫表中的所有列。

僅供參考使用Teradata作爲DB,Spring,JPA,JSF。

+1

我沒有看到你在Persistence.xml中映射你的實體類ParamConfiguration,但是你可以在你的實體中有沒有在數據庫中有等價物的字段,但他們需要用@Transient註解 – drgPP

+0

哦,你的存在文件必須是'persistence.xml',而不是persistance.xml –

回答

0

ParamConfiguration實體沒有在persistence.xml文件中列出您設置的選項exclude-unlisted-classestrue

添加到您的persistence.xml文件:

<class>net.odcorp.sas.mrm.beans.ParamConfiguration</class> 

肯定的是,包好。

+0

設置'exclude-unlisted-classes'爲true不會選取所有帶註釋的實體類。 –

+0

它不工作......是否強制將表中的所有列添加到實體類 –

+0

否它不是強制性的 –

1

在persistence.xml文件試試這個,

<persistence-unit name="serCoupons_Cdm" transaction-type="RESOURCE_LOCAL"> 
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> 
<non-jta-data-source>jdbc/CDM</non-jta-data-source> 
<exclude-unlisted-classes>false<exclude-unlisted-classes/> 

exclude-unlisted-classes,因爲它的默認值有真。或者如果將其設置爲true,則需要手動指定標籤列出這些實體類,

<class>com.package.Class</class> 
0

我有同樣的問題,但對我來說,我錯過了 @Table註解。另外在我的代碼中不要使用@Column註解,我在@Id下面使用@GeneratedValue(strategy = GenerationType.IDENTITY)。它適用於我沒有使用

<exclude-unlisted-classes>true</exclude-unlisted-classes> 

我可以提供我的源代碼,因爲我剛剛用於瞭解JPA。

相關問題