我的 JPA 代码在 eclipse Helios 中编译良好,在生产中运行良好。但是在较新版本的 Eclipse 中,使用 javax.persistence.* 包中的注释 @IdClass 时出现错误“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>
我暂时关闭了错误通知,但为什么会发生这种情况?