我有一个SQL查询
select * from LEASINGPRODUCTGROUP lg join DFE_APPLICATION da ON lg.APPLICATIONID = da.id where lg.applicationid in (1,62);
DFE_APPLICATION是我已经决定的实体,因为我只需要该表中的ID,因此在我的命名查询中,我决定使用私有列表应用程序; 如下所述
public class LeasingProductGroupOB extends BaseOB {
@ElementCollection
private List<Long> applications;
@JoinTable(name = "LEASINGPRODUCTGROUPAPP", joinColumns = {
@JoinColumn(name = "GROUPID", referencedColumnName = "ID", nullable = false) }, inverseJoinColumns = {
@JoinColumn(name = "APPID", referencedColumnName = "ID", nullable = false) })
@ManyToMany(fetch = FetchType.LAZY)
public List<Long> getApplications() {
return applications;
}
public void setApplications(List<Long> applications) {
this.applications = applications;
}
}
Now i want to perform the sql query as above only now i dont have the whole entity, Im not sure exactly how to go about it.
My idea
first leasingproductgroup has
id, name, applicationid on the table
dfe_application has
ID, EMvalue, name
The manytomany relationship has a table
LEASINGPRODUCTGROUPAPP with ids and fk from dfe_application and leasingproductgroup
Using named query i got stopped here as am not sure how to continue since in the class i have list<Long> of applications and not the whole entity.
@NamedQuery(name = "LeasingProductGroupOB.findActiveByApp", query = "SELECT p FROM LeasingProductGroupOB p join fetch p.applications a p.applicationId = a. "
关于如何继续的任何建议?