У меня есть DecisionEntity, который имеет двунаправленное отношение OneToMany к ExplanationEntity. SpecificDecisionEntity расширяет DecisionEntity и добавляет однонаправленное отношение manyToOne к CharacteristicEntity по полю, отличному от id. Я создал SpecificDecision с одним связанным ExplanationEntity. Но когда я попытался выбрать эту сущность, я получил список с 3 записями одной и той же сущности вместо 1 ... Что не так?
CharacteristicEntity:
@Entity
public class CharacteristicEntity extends BaseEntity {
private Long xid;
public Long getXid() {
return xid;
}
...
ExplanationEntity:
@Entity
public class ExplanationEntity extends BaseEntity {
...
private DecisionEntity decision;
@ManyToOne(cascade={CascadeType.REFRESH, CascadeType.PERSIST}, fetch=FetchType.EAGER, optional=false)
public DecisionEntity getDecision() {
return decision;
}
public void setDecision(DecisionEntity decision) {
this.decision = decision;
}
}
DecisionEntity:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="decisionType")
public abstract class DecisionEntity extends BaseEntity {
private Date date;
private List<ExplanationEntity> explanations;
private DefinitionEntity definition;
private DecisionTypeEnum decisionType;
private DecisionEntity parent;
private List<DecisionEntity> subDecisions;
@Temporal(TemporalType.DATE)
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
@OneToMany(cascade={CascadeType.REFRESH, CascadeType.PERSIST}, mappedBy="hachlata", fetch=FetchType.EAGER)
public List<ExplanationEntity> getExplanations() {
return explanations;
}
public void setExplanations(List<ExplanationEntity> explanations) {
this.explanations = explanations;
}
@ManyToOne(optional=false, fetch=FetchType.EAGER)
public DefinitionEntity getDefinition() {
return definition;
}
public void setDefinition(DefinitionEntity definition) {
this.definition = definition;
}
@Enumerated(EnumType.STRING)
public DecisionTypeEnum getDecisionType() {
return decisionType;
}
public void setDecisionType(DecisionTypeEnum decisionType) {
this.decisionType = decisionType;
}
@ManyToOne(optional=true, cascade={CascadeType.PERSIST, CascadeType.REFRESH})
public DecisionEntity getParent() {
return parent;
}
public void setParent(DecisionEntity parent) {
this.parent = parent;
}
@OneToMany(mappedBy="parent", fetch=FetchType.LAZY, cascade={CascadeType.PERSIST, CascadeType.REFRESH})
public List<DecisionEntity> getSubDecisions() {
return subDecisions;
}
public void setSubDecisions(List<DecisionEntity> subDecisions) {
this.subDecisions = subDecisions;
}
}
SpecificDecisionEntity:
@Entity
@DiscriminatorValue("specific")
@NamedQueries({
@NamedQuery(name="getSpecificDecisionByCharacteristicId", query="SELECT s FROM SpecificDecisionEntity s WHERE s.characteristic.xid = :xid")
})
public class SpecificDecisionEntity extends HachlataEntity {
private boolean value;
private CharacteristicEntity characteristic;
public boolean isValue() {
return value;
}
public void setValue(boolean value) {
this.value = value;
}
@ManyToOne(cascade=CascadeType.REFRESH, optional=false)
@JoinColumn(referencedColumnName="xid", nullable=false)
public CharacteristicEntity getCharacteristic() {
return characteristic;
}
public void setCharacteristic(CharacteristicEntity characteristic) {
this.characteristic = characteristic;
}
}