基本上,我的搜索使用的是大sql视图来检索数据,现在我必须将搜索功能扩展到从单独的视图获取的另一个字段。
我遵循了此link中的步骤,但被卡住了。
我想在视图V_FPDA_FILE_RTL_UNT和V_FPDA_FILE_UK_CONTN之间创建多对多关系。
我将表FpdaFileDetail映射到V_FPDA_FILE_RTL_UNT视图。
@Entity(name="FpdaFileDetail")
@Table(name="V_FPDA_FILE_RTL_UNT")
@AttributeOverrides({ @AttributeOverride(name = "id", column = @Column(name = "FPDA_FILE_ID")) })
public class FpdaFileDetail {
...
@ManyToMany
@Fetch(FetchMode.SUBSELECT)
@JoinTable(name = "V_FPDA_FILE_UK_CONTN", joinColumns = { @JoinColumn(name = "FPDA_FILE_ID") }, inverseJoinColumns = {@JoinColumn(name = "UK_CMPT_CONTN_ID")})
public Set<UkComponentContent> getUkContentIds() {
return ukContentIds;
}
public void setUkContentIds(Set<UkComponentContent> ukContentIds) {
this.ukContentIds = ukContentIds;
}
我创建的多对多关系是这样制作的:
@Entity
@Table(name="UK_CONTN")
@AttributeOverrides({ @AttributeOverride(name = "id", column = @Column(name = "UK_CONTN_ID")) })
public class UkContent {
private static final long serialVersionUID = 1L;
private String contentId;
private Set<UkComponentContent> ukComponentContents;
@Column(name = "UK_CONTN")
public String getContentId() {
return contentId;
}
public void setContentId(String contentId) {
this.contentId = contentId;
}
@OneToMany(
mappedBy = "ukContent",
cascade = CascadeType.ALL,
orphanRemoval = true
)
public Set<UkComponentContent> getUkComponentContents() {
return ukComponentContents;
}
public void setUkComponentContents(Set<UkComponentContent> ukComponentContents) {
this.ukComponentContents = ukComponentContents;
}
}
@Entity(name = "FpdaFile")
@Table(name = "FPDA_FILE")
@AttributeOverrides({ @AttributeOverride(name = "id", column = @Column(name = "FPDA_FILE_ID")) })
public class FpdaFile {
...
private Set<UkComponentContent> ukContentIds = new HashSet<UkComponentContent>(0);
@OneToMany(mappedBy = "fpdaFile")
public Set<UkComponentContent> getUkContentIds() {
return ukContentIds;
}
public void setUkContentIds(Set<UkComponentContent> ukContentIds) {
this.ukContentIds = ukContentIds;
}
}
@Entity
@Table(name="UK_CMPT_CONTN")
@AttributeOverrides({ @AttributeOverride(name = "id", column = @Column(name = "UK_CMPT_CONTN_ID")) })
public class UkComponentContent extends BaseEntity {
private FpdaFile fpdaFile;
private UkContent ukContent;
@ManyToOne
@JoinColumn(name = "FPDA_FILE_ID")
public FpdaFile getFpdaFile() {
return fpdaFile;
}
public void setFpdaFile(FpdaFile fpdaFile) {
this.fpdaFile = fpdaFile;
}
@ManyToOne
@JoinColumn(name = "UK_CONTN_ID")
public UkContent getUkContent() {
return ukContent;
}
public void setUkContent(UkContent ukContent) {
this.ukContent = ukContent;
}
}
问题是,如果我让这样的代码执行,则搜索将无法进行,但不会引发任何错误。通过调试,我意识到,如果我对此进行评论(来自FpdaFileDetail)。
@ManyToMany
@Fetch(FetchMode.SUBSELECT)
@JoinTable(name = "V_FPDA_FILE_UK_CONTN", joinColumns = { @JoinColumn(name = "FPDA_FILE_ID") }, inverseJoinColumns = {@JoinColumn(name = "UK_CMPT_CONTN_ID")})
public Set<UkComponentContent> getUkContentIds() {
return ukContentIds;
}
public void setUkContentIds(Set<UkComponentContent> ukContentIds) {
this.ukContentIds = ukContentIds;
搜索将起作用。但是,如果不加注释,它将无法正常工作。
欢迎提出任何想法!