2012-06-26 39 views
0

我有JPA代碼,編譯在eclipse Helios罰款,並在生產中工作正常。但是在新版本的eclipse中,當使用javax.persistence。*包中的註解@IdClass時,出現錯誤「不應映射ID類」。JPA錯誤:ID類不應該映射

@Entity 
@IdClass(RetailLocationPK.class) // Generates "ID class should not be mapped" error 
@Table(name="loc_rtl_loc") 
public class RetailLocation implements Serializable { 
    @Id 
    @Column(name="organization_id")  
    private int organizationId; 

    @Id 
    @Column(name="rtl_loc_id") 
    private int rtlLocId; 
... 
} 

然後在RetailLocationPK.java我:

@Embeddable 
public class RetailLocationPK implements Serializable { 
    //default serial version id, required for serializable classes. 
    private static final long serialVersionUID = 1L; 
    @Column(name="organization_id") 
    private int organizationId; 

    @Column(name="rtl_loc_id") 
    private int rtlLocId; 

    public RetailLocationPK() { 
    } 
    ... 
} 

最後,在persistence.xml中,我有:

<persistence-unit name="taxPu" transaction-type="JTA"> 
    <class>tbss.persist.RetailLocation</class> 
    <class>tbss.persist.RetailLocationPK</class> 
    ... 
</persistence-unit> 

我已經關閉了錯誤通知了,但爲什麼會發生?

回答

0

我不確定它不應該如此,但@IdClass(與@EmbeddedId不同)絕對不一定是@Embeddable並且與<class>對應。

+0

我從PK類中刪除了@Embeddable,並從persistence.xml文件中刪除了其元素,錯誤消失了。現在來測試它。 –