与@EmbeddedId映射时发生Eclipse错误 [英] Eclipse error on mapping with @EmbeddedId

查看:569
本文介绍了与@EmbeddedId映射时发生Eclipse错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有组合键的实体,所以我使用@Embeddable和@EmbeddedId注解。
Embeddable类看起来像这样:

  @Embeddable 
public class DitaAdminAccountSkillPK实现Serializable {

@ManyToOne
@JoinColumn(name =admin_id)
私人DitaAdmin管理员;

@ManyToOne
@JoinColumn(name =account_id)
私人DitaAccount帐户;

//构造函数,getters,setters ...
}



<

  @Entity 
public class DitaAdminAccountSkill {

@EmbeddedId
私人DitaAdminAccountSkillPK ID;

//构造函数,getters,setters ...
}

现在我想将实体映射到另一个实体中,如下所示:

  @OneToMany(fetch = FetchType.LAZY,mappedBy = id.admin)
私人列表< DitaAdminAccountSkill> accountSkills;

请注意 mappedBy =id.admin,它指 DitaAdminAccountSkill id 字段在 DitaAdminAccountSkillPK 中添加 字段。

<这个编译和运行很好。然而,在eclipse中显示的错误是:
在属性'accountSkills'中,映射的值'id.admin'无法解析为目标实体的属性。



请注意,这是 JPA问题,这意味着JPA方面正在抱怨。
现在,我知道我可以使用@IdClass,但我只是想知道为什么它认为它是一个错误。或者,也许我做了一些非常错误的事情?



感谢指针,Zbynek

解决方案

根据 JPA 2.0规范嵌入式id类中定义的关系映射不受支持。但是,可能由JPA实现支持即使标准本身没有官方支持,也是如此。



如果在这里出现这种情况,您可能需要在Eclipse下的 Window - >首选项 - > Java持久性 - > JPA - >错误/警告 - >属性 - >无法解析属性名称


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 ?

Thanks for pointers, Zbynek

解决方案

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.

这篇关于与@EmbeddedId映射时发生Eclipse错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆