2011-04-15 51 views
0

我正在使用由Netbeans生成的一些實體。後代我測試了他們,他們工作正常。所以我不得不轉移到下一步,並將這些與我的JAXB對象結合起來。與JAXB對象結合後,我可以解組我的XML流而不會出現問題。但是當我嘗試使用任何相關類的任何類時,我會遇到一些錯誤。Eclipslink - 未知實體類型

我現在又回到了測試階段,這就是我所擁有的。我有一個簡單的主要方法運行測試類。我用於最初測試實體的相同設置。下面你會看到測試類,類實體,導致問題JoinAssetToSku的實體和錯誤。我忽略了實體的大多數制定者和獲得者。有誰知道這個JoinAssetToSku.findByTs查詢有什麼問題。我不明白它是如何導致這種錯誤,它不是自我意識!

的代碼做的測試:

public void testClassEntity(){ 
     testClass = new Classes(1); 
     testClass.setClassId("12"); 
     testClass.setDescription("The First Class"); 
     testClass.setTs(new java.sql.Timestamp(new Date().getTime())); 
     ClassesJpaController cc = new ClassesJpaController(); 
      try { 
       cc.create(testClass); 
      } catch (PreexistingEntityException ex) { 
       Logger.getLogger(EntityTest.class.getName()).log(Level.SEVERE, null, ex); 
      } catch (Exception ex) { 
       Logger.getLogger(EntityTest.class.getName()).log(Level.SEVERE, null, ex); 
      } 
    } 

的類類:

package entitiesjaxb.cmic.ajrs.com; 

import java.io.Serializable; 
import java.util.Collection; 
import java.util.Date; 
import javax.persistence.Basic; 
import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.FetchType; 
import javax.persistence.Id; 
import javax.persistence.NamedQueries; 
import javax.persistence.NamedQuery; 
import javax.persistence.OneToMany; 
import javax.persistence.Table; 
import javax.persistence.Temporal; 
import javax.persistence.TemporalType; 
import javax.xml.bind.annotation.XmlRootElement; 
import javax.xml.bind.annotation.XmlAccessType; 
import javax.xml.bind.annotation.XmlAccessorType; 
import javax.xml.bind.annotation.XmlElement; 
import javax.xml.bind.annotation.XmlSchemaType; 
import javax.xml.bind.annotation.XmlTransient; 
import javax.xml.bind.annotation.XmlType; 

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "Classes", propOrder = { 
    "pkId", 
    "classId", 
    "description", 
    "ts" 
}) 

@Entity 
@Table(name = "classes") 
@NamedQueries({ 
    @NamedQuery(name = "Classes.findAll", query = "SELECT c FROM Classes c"), 
    @NamedQuery(name = "Classes.findByPkId", query = "SELECT c FROM Classes c WHERE c.pkId = :pkId"), 
    @NamedQuery(name = "Classes.findByClassId", query = "SELECT c FROM Classes c WHERE c.classId = :classId"), 
    @NamedQuery(name = "Classes.findByDescription", query = "SELECT c FROM Classes c WHERE c.description = :description"), 
    @NamedQuery(name = "Classes.findByTs", query = "SELECT c FROM Classes c WHERE c.ts = :ts")}) 
public class Classes implements Serializable { 
    private static final long serialVersionUID = 1L; 
    @Id 
    @Basic(optional = false) 
    @Column(name = "pk_id") 
    private Integer pkId; 
    @Column(name = "class_id") 
    @XmlElement(name = "ClassID") 
    private String classId; 
    @Column(name = "description") 
    @XmlElement(name = "Description") 
    private String description; 
    @Basic(optional = false) 
    @Column(name = "ts") 
    @Temporal(TemporalType.TIMESTAMP) 
    @XmlElement(required = true) 
    @XmlSchemaType(name = "dateTime") 
    private Date ts; 
    @OneToMany(mappedBy = "classes", fetch = FetchType.LAZY) 
    @XmlTransient 
    private Collection<Categories> categoriesCollection; 

    public Classes() { 
    } 

    public Classes(Integer pkId) { 
     this.pkId = pkId; 
    } 

    public Classes(Integer pkId, Date ts) { 
     this.pkId = pkId; 
     this.ts = ts; 
    } 

類導致錯誤:

package entitiesjaxb.cmic.ajrs.com; 

import java.io.Serializable; 
import java.util.Date; 
import javax.persistence.Basic; 
import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.FetchType; 
import javax.persistence.Id; 
import javax.persistence.JoinColumn; 
import javax.persistence.ManyToOne; 
import javax.persistence.NamedQueries; 
import javax.persistence.NamedQuery; 
import javax.persistence.Table; 
import javax.persistence.Temporal; 
import javax.persistence.TemporalType; 
import javax.xml.bind.annotation.XmlAccessType; 
import javax.xml.bind.annotation.XmlAccessorType; 
import javax.xml.bind.annotation.XmlElement; 
import javax.xml.bind.annotation.XmlSchemaType; 
import javax.xml.bind.annotation.XmlType; 

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "JoinAssetToSKU", propOrder = { 
    "pkId", 
    "assetData", 
    "skuBasic", 
    "ts" 
}) 

@Entity 
@Table(name = "join_asset_to_sku") 
@NamedQueries({ 
    @NamedQuery(name = "JoinAssetToSku.findAll", query = "SELECT j FROM JoinAssetToSku j"), 
    @NamedQuery(name = "JoinAssetToSku.findByPkId", query = "SELECT j FROM JoinAssetToSku j WHERE j.pkId = :pkId"), 
    @NamedQuery(name = "JoinAssetToSku.findByTs", query = "SELECT j FROM JoinAssetToSku j WHERE j.ts = :ts")}) 
public class JoinAssetToSKU implements Serializable { 
    private static final long serialVersionUID = 1L; 
    @Id 
    @Basic(optional = false) 
    @Column(name = "pk_id") 
    private Integer pkId; 
    @Column(name = "ts") 
    @Temporal(TemporalType.TIMESTAMP) 
    @XmlElement(required = true) 
    @XmlSchemaType(name = "dateTime") 
    private Date ts; 
    @JoinColumn(name = "pk_sku", referencedColumnName = "pk_id") 
    @ManyToOne(fetch = FetchType.LAZY) 
    private SKUBasic skuBasic; 
    @JoinColumn(name = "pk_asset", referencedColumnName = "pk_id") 
    @ManyToOne(fetch = FetchType.LAZY) 
    private AssetData assetData; 

    public JoinAssetToSKU() { 
    } 

    public JoinAssetToSKU(Integer pkId) { 
     this.pkId = pkId; 
    } 

    public Integer getPkId() { 
     return pkId; 
    } 

    public void setPkId(Integer pkId) { 
     this.pkId = pkId; 
    } 

我得到的錯誤。

[EL Info]: 2011-04-15 08:26:58.223--ServerSession(2128911821)--EclipseLink, version: Eclipse Persistence Services - 2.0.2.v20100323-r6872 
[EL Severe]: 2011-04-15 08:26:58.525--ServerSession(2128911821)--Local Exception Stack: 
Exception [EclipseLink-8034] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.JPQLException 
Exception Description: Error compiling the query [JoinAssetToSku.findByTs: SELECT j FROM JoinAssetToSku j WHERE j.ts = :ts]. Unknown entity type [JoinAssetToSku]. 
     at org.eclipse.persistence.exceptions.JPQLException.entityTypeNotFound(JPQLException.java:483) 
     at org.eclipse.persistence.internal.jpa.parsing.ParseTreeContext.classForSchemaName(ParseTreeContext.java:138) 
     at org.eclipse.persistence.internal.jpa.parsing.SelectNode.getClassOfFirstVariable(SelectNode.java:327) 
     at org.eclipse.persistence.internal.jpa.parsing.SelectNode.getReferenceClass(SelectNode.java:316) 
     at org.eclipse.persistence.internal.jpa.parsing.ParseTree.getReferenceClass(ParseTree.java:439) 
     at org.eclipse.persistence.internal.jpa.parsing.ParseTree.adjustReferenceClassForQuery(ParseTree.java:79) 
     at org.eclipse.persistence.internal.jpa.parsing.JPQLParseTree.populateReadQueryInternal(JPQLParseTree.java:103) 
     at org.eclipse.persistence.internal.jpa.parsing.JPQLParseTree.populateQuery(JPQLParseTree.java:84) 
     at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:202) 
     at org.eclipse.persistence.internal.jpa.JPAQuery.processJPQLQuery(JPAQuery.java:106) 
     at org.eclipse.persistence.internal.jpa.JPAQuery.prepare(JPAQuery.java:90) 
     at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:464) 
     at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:430) 
     at org.eclipse.persistence.internal.sessions.AbstractSession.processJPAQueries(AbstractSession.java:1747) 
     at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:409) 
     at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:671) 
     at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:620) 
     at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:228) 
     at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:369) 
     at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:151) 
     at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:207) 
     at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:195) 
     at controllers.cmic.ajrs.com.ClassesJpaController.getEntityManager(ClassesJpaController.java:33) 
     at controllers.cmic.ajrs.com.ClassesJpaController.create(ClassesJpaController.java:42) 
     at cmicpojo.EntityTest.testClassEntity(EntityTest.java:33) 
     at cmicpojo.Main.main(Main.java:45) 

[EL Info]: 2011-04-15 08:26:58.545--ServerSession(2128911821)--EclipseLink, version: Eclipse Persistence Services - 2.0.2.v20100323-r6872 
Apr 15, 2011 8:26:58 AM cmicpojo.EntityTest testClassEntity 
SEVERE: null 
Local Exception Stack: 
Exception [EclipseLink-7092] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.ValidationException 
Exception Description: Cannot add a query whose types conflict with an existing query. Query To Be Added: [ReadAllQuery(name="KeyFeatures.findByBasicDescription" referenceClass=KeyFeatures jpql="SELECT k FROM KeyFeatures k WHERE k.basicDescription = :basicDescription")] is named: [KeyFeatures.findByBasicDescription] with arguments [[class java.lang.String]].The existing conflicting query: [ReadAllQuery(name="KeyFeatures.findByBasicDescription" referenceClass=KeyFeatures jpql="SELECT k FROM KeyFeatures k WHERE k.basicDescription = :basicDescription")] is named: [KeyFeatures.findByBasicDescription] with arguments: [[class java.lang.String]]. 
     at org.eclipse.persistence.exceptions.ValidationException.existingQueryTypeConflict(ValidationException.java:895) 
     at org.eclipse.persistence.internal.sessions.AbstractSession.addQuery(AbstractSession.java:388) 
     at org.eclipse.persistence.internal.sessions.AbstractSession.addQuery(AbstractSession.java:360) 
     at org.eclipse.persistence.internal.sessions.AbstractSession.processJPAQueries(AbstractSession.java:1749) 
     at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:409) 
     at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:671) 
     at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:633) 
     at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:214) 
     at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:195) 
     at controllers.cmic.ajrs.com.ClassesJpaController.getEntityManager(ClassesJpaController.java:33) 
     at controllers.cmic.ajrs.com.ClassesJpaController.findClasses(ClassesJpaController.java:174) 
     at controllers.cmic.ajrs.com.ClassesJpaController.create(ClassesJpaController.java:62) 
     at cmicpojo.EntityTest.testClassEntity(EntityTest.java:33) 
     at cmicpojo.Main.main(Main.java:45) 

回答

0

這是我的一個錯誤,將生成的實體和生成的JAXB類組合在一起導致我導致某些類名稱不正確。

類名應該是JoinAssetToSku以匹配指定的查詢。或者我可以將類名稱保留爲JoinAssetToSKU並更改指定的查詢。

我選擇改變類名。

相關問題