我有两个实体形成多对多关系。每个Spectrum
都与另一个Spectrum
匹配,其相似度得分存储在SpectrumMatch
中。
@Entity
public class Spectrum {
private long id;
private List<SpectrumMatch> matches;
private List<SpectrumMatch> matches2;
@OneToMany(targetEntity = SpectrumMatch.class,
mappedBy = "querySpectrum",
fetch = FetchType.LAZY,
cascade = Cascade.ALL)
public List<SpectrumMatch> getMatches()
@OneToMany(targetEntity = SpectrumMatch.class,
mappedBy = "matchSpectrum",
fetch = FetchType.LAZY,
cascade = Cascade.ALL)
public List<SpectrumMatch> getMatches2()
}
@Entity
public class SpectrumMatch {
private long id;
@NotNull
private Spectrum querySpectrum;
@NotNull
private Spectrum matchSpectrum;
private double score;
@ManyToOne(fetch = FetchType.EAGER, optional = false)
@JoinColumn(name = "QuerySpectrumId", referencedColumnName = "Id")
public Spectrum getQuerySpectrum();
@ManyToOne(fetch = FetchType.EAGER, optional = false)
@JoinColumn(name = "MatchSpectrumId", referencedColumnName = "Id")
public Spectrum getMatchSpectrum()
}
在此代码中,字段Spectrum.matches
包含SpectrumMatch
的所有实例,其中SpectrumMatch.querySpectrum.id
等于Spectrum.id
。
但是,我希望字段Spectrum.matches
包含SpectrumMatch
的所有实例,其中 SpectrumMatch.querySpectrum.id
或 {{1等于SpectrumMatch.matchSpectrum.id
。
是否有可能实现这种关系?