我有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>
我暂时关闭了错误通知,但为什么会这样呢?
答案 0 :(得分:0)
我不确定它不应该是,但是@IdClass
(与@EmbeddedId
不同)肯定不一定是@Embeddable
并且与<class>
映射。