我有一个实体类,如下所示
ExportMO.java
@Entity
@Table(name = "DATAEXPORTTEMPLATE")
@NamedQueries({
@NamedQuery(name = "ExportTemplateMO.getTemplatesByUser", query = "SELECT DISTINCT template FROM ExportTemplateMO template " +
"join template.fields exportFields WHERE template.eId IN (SELECT S1.dcid FROM SchoolMO S1 join S1.fields S2 WHERE S2.dcid = :userDCID)")
})
public class ExportMO implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "DATATEMPLATEID", unique = true, nullable = false)
private Long templateId;
@Column(name = "EID", nullable = true)
private Long eId;
@OneToMany(fetch=FetchType.EAGER, mappedBy="templateMO", cascade={CascadeType.ALL}, orphanRemoval=true)
private Set<ExportFieldMO> fields;
}
SchoolMO.java
@Entity
@Table(name = "SCHOOLSTAFF")
public class SchoolMO implements Serializable {
@Id
@Column(name = "DCID", unique = true, nullable = false)
private Long dcid;
@Column(name = "ID", unique = true)
private Long id;
@Column(name = "USERS_DCID", unique = false, nullable = false)
@JoinColumn(name="USERS_DCID",referencedColumnName="USERS_DCID",nullable=false)
private Long users_dcid;
@OneToMany(fetch=FetchType.EAGER, mappedBy="users_dcid", cascade={CascadeType.ALL}, orphanRemoval=true)
private Set<SchoolStaffLeanMO> fields;
}
有人可以帮助我使用子句面的IN子句来使用它。 如果我尝试使用相同的'='而不是'IN',我就能得到结果。
提前致谢。