各クラスがエンティティを拡張するモデルがあります:
@MappedSuperclass
public abstract class Entity implements Serializable {
private Long id;
.
.
.
}
さて、私のモデルでは、各エンティティは属性を持つことができます:
@javax.persistence.Entity
public class Attribute extends Entity {
private Entity entity;
private String name;
private String value;
.
.
.
}
私の質問は次のとおりです。クラス Attribute のエンティティ属性をマップするにはどうすればよいですか? 私の考えは、この属性をentityClassとentityIdとして保存することですが、それでもJPAでこれを達成する方法がわかりませんか?
エンティティを拡張する具象クラスの例:
@javax.persistence.Entity
public class Ball extends Entity {
private Set<Attribute> attributes;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "entity")
public Set<Attribute> getAttributes() {
return attributes;
}
public void setAttributes(Set<Attribute> attributes) {
this.attributes = attributes;
}
}