我有以下实体:Match
,具有embeddableId MatchKey
和多态实体OrganisationMatch
休眠状态Repeated column in mapping for entity: net.satago.web.entities.OrganisationMatch column: referenceKind (should be mapped with insert="false" update="false")
我不知道出什么问题了,我不能在@DiscriminatorColumn
的各个部分上使用@EmbeddableId
注释,并使它们不可插入或不可更新吗?
如果要区分的列不是@EmbeddableId
的一部分,而只是Match
实体上的常规列,则效果很好。
@Embeddable
@ParametersAreNonnullByDefault
public class MatchKey implements Serializable
{
private static final long serialVersionUID = 7619427612022530146L;
@Column(insertable = false, updatable = false)
@Enumerated(STRING)
private MatchableEntityKind referenceKind;
private Long referenceId;
public MatchKey()
{
// For JPA
}
public MatchKey(OrganisationId organisationId)
{
this.referenceKind = ORGANISATION;
this.referenceId = organisationId.getId();
}
public MatchableEntityKind getReferenceKind()
{
return referenceKind;
}
public void setReferenceKind(MatchableEntityKind referenceKind)
{
this.referenceKind = referenceKind;
}
public Long getReferenceId()
{
return referenceId;
}
public void setReferenceId(Long referenceId)
{
this.referenceId = referenceId;
}
@Override
public boolean equals(Object obj)
{
if (obj instanceof MatchKey)
{
MatchKey that = (MatchKey) obj;
return this.referenceKind == that.referenceKind &&
Objects.equals(this.referenceId, that.referenceId);
}
return false;
}
@Override
public int hashCode()
{
return Objects.hash(referenceKind, referenceId);
}
}
@Entity
@Table(name = TABLE_NAME)
@Inheritance(strategy = SINGLE_TABLE)
@DiscriminatorColumn(name = "reference_kind", discriminatorType = DiscriminatorType.STRING)
@ParametersAreNonnullByDefault
public class Match implements EntityModel<MatchKey>
{
static final String TABLE_NAME = "matches";
@EmbeddedId
private MatchKey id;
@Version
private Long version;
... generic match columns
}
和
@Entity
@DiscriminatorValue(OrganisationMatch.REFERENCE_KIND)
@ParametersAreNonnullByDefault
public class OrganisationMatch extends Match
{
static final String REFERENCE_KIND = "ORGANISATION";
@JoinColumn(name = "reference_id")
@OneToOne(fetch = LAZY, optional = false)
private Organisation organisation;
public OrganisationMatch()
{
setReferenceKind(MatchableEntityKind.valueOf(REFERENCE_KIND));
}
public OrganisationMatch(OrganisationId organisationId)
{
super(new MatchKey(organisationId));
setReferenceKind(MatchableEntityKind.valueOf(REFERENCE_KIND));
}
public Organisation getOrganisation()
{
return organisation;
}
}