I have an entity with composite key so I use the @Embeddable and @EmbeddedId annotations. Embeddable class looks like this :
@Embeddable
public class DitaAdminAccountSkillPK implements Serializable {
@ManyToOne
@JoinColumn(name = "admin_id")
private DitaAdmin admin;
@ManyToOne
@JoinColumn(name = "account_id")
private DitaAccount account;
//constructor, getters, setters...
}
And the entity that uses it :
@Entity
public class DitaAdminAccountSkill {
@EmbeddedId
private DitaAdminAccountSkillPK id;
//constructor, getters, setters...
}
Now I want to map the entity in another entity like this :
@OneToMany(fetch = FetchType.LAZY, mappedBy = "id.admin")
private List<DitaAdminAccountSkill> accountSkills;
Notice the mappedBy = "id.admin" which refers to admin field in DitaAdminAccountSkillPK using the id field of DitaAdminAccountSkill.
This compiles and runs just fine. However, in eclipse there is an error displayed that says : In attribute 'accountSkills', the "mapped by" value 'id.admin' cannot be resolved to an attribute on the target entity.
Note that this is a JPA Problem meaning the JPA facet is complaining. Now, I know I could use @IdClass instead but I am just wondering why does it think its an error. Or maybe I do something terribly wrong ?
According to section 11.1.15 of the JPA 2.0 specification: Relationship mappings defined within an embedded id class are not supported. However, this might be supported by the JPA implementation you're using, even if it's not officially supported by the standard itself.
If this is the case here, you might want to turn off validation for this in Eclipse under Window -> Preferences -> Java Persistence -> JPA -> Errors/Warnings -> Attributes -> Cannot resolve attribute name
.