我有一个模型,每个类都扩展实体:
@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;
}
}