I have JPA code that compiles fine in eclipse Helios and works fine in production. But in a newer version of eclipse, I am getting the error “ID class should not be mapped” when using the annotation @IdClass from javax.persistence.* package.
@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;
...
}
Then in RetailLocationPK.java I have:
@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() {
}
...
}
Finally, in persistence.xml, I have:
<persistence-unit name="taxPu" transaction-type="JTA">
<class>tbss.persist.RetailLocation</class>
<class>tbss.persist.RetailLocationPK</class>
...
</persistence-unit>
I have turned off the error notification for now, but why does this happen?
I’m not sure that it shouldn’t be, but
@IdClass(unlike@EmbeddedId) definitely doesn’t have to be@Embeddableand mapped with<class>.