是否可以执行以下操作...
我有一个名为 Action 的 MappedSuperclass:
@MappedSuperclass
public class Action extends EntityBase
{
private static final long serialVersionUID = 2604473746836781718L;
private String event;
public String getEvent()
{
return event;
}
public void setEvent(String event)
{
this.event = event;
}
}
此外,我有 2 个从此类派生的类(实体),例如 GenericAction:
@Entity
@Table(name = "GENERIC_ACTION")
@AttributeOverrides({@AttributeOverride(name = "id", column = @Column(name = "GAC_ID")),
@AttributeOverride(name = "version", column = @Column(name = "GAC_VERSION")), @AttributeOverride(name = "event", column = @Column(name = "GAC_EVENT"))})
public class GenericAction extends Action
{
private static final long serialVersionUID = 2694061082912048881L;
@Column(name = "GAC_PAYLOAD")
private String payload;
public String getPayload()
{
return payload;
}
public void setPayload(String payload)
{
this.payload = payload;
}
}
在另一个名为 Journal 的实体中,有这个 Action 属性集:
@Entity
@Table(name = "JOURNAL")
@AttributeOverrides({@AttributeOverride(name = "id", column = @Column(name = "JRN_ID")),
@AttributeOverride(name = "version", column = @Column(name = "JRN_VERSION"))})
public class Journal extends EntityBase
{
private static final long serialVersionUID = 2525323851057436815L;
@Column(name = "JRN_ACTION")
private Action action;
}
在我的代码中,我实例化了 GenericAction 并使用 Journal 的 setter 进行设置。当 Journal 将被持久化时,它应该将 GenericAction 的内容保存在自己的表中,但这不会发生。它将GenericAction 的字节码保存到Journal 的Action 字段中。
这可能吗?