[英]Eclipse IDE showing error for Composite Primary Key classes in JPA
我有一个带有复合 PK 的实体类,如下所示:
使用 @Embeddable 和 @EmbeddedId 注释。
/** The primary key class for the uom_conversion database table. */
@Embeddable
public class UomConversionPK implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name="product_id", insertable=false, updatable=false)
private int productId;
@Column(name="base_uom_id", insertable=false, updatable=false)
private int baseUomId;
@Column(name="to_unit_id", insertable=false, updatable=false)
private int toUnitId;
//getters, setters
}
使用它的实体是:
/** The persistent class for the uom_conversion database table. */
@Entity
@Table(name="uom_conversion")
public class UomConversion implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private UomConversionPK id;
}
这里 Eclipse 显示错误:“UomConversionPK 无法解析为类型”
在另一个项目中,我将实体与复合 PK 一起使用,没有任何错误。
现在这似乎是 JPA 方面的问题,想知道为什么 Eclipse 无法解决 UomConversionPK 或者我做错了什么?
好吧,当使用 JPA 工具从表创建 JPA 实体时,@ @EmbeddedId
注释有时会发生此错误,但并非总是如此。
在我的情况下,直到我将以下内容设置为Ignore
然后回到Error
之前,这个问题才得到解决:
Windows -> Preferences -> Java Persistence -> JPA -> Errors/Warnings -> Attribute -> Embedded ID classes should implement hashcode() and equals()
。 即使 Embeddable 类确实具有 hashcode() 和 equals() 方法实现,也会发生此错误。 可能这也适用于您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.