我编写了一个联接查询,如果在SQL开发人员上使用ON子句进行了测试,则可以正常工作并返回结果,但是当我使用名称查询执行此操作时,我得到0个结果,但没有错误。
sql开发人员上的sql查询是
select * from LEASINGPRODUCTGROUP lg join DFE_APPLICATION da ON lg.APPLICATIONID = da.id where da.id =3;
And returns about 5 results
但是我需要使用命名查询,并且我正在使用联接获取
这是课程
@Entity
@Table(name = "LEASINGPRODUCTGROUP")
@NamedQueries({
@NamedQuery(name = "LeasingProductGroupOB.findByAppid", query = "SELECT p FROM LeasingProductGroupOB p join fetch p.applications aa WHERE aa.id = :appid ORDER BY p.idx asc") })
@SequenceGenerator(allocationSize = 1, name = "SEKWENCJA", sequenceName = "GEN_LEASINGPRODUCTGROUP_ID")
public class LeasingProductGroupOB extends BaseOB {
private String nazwa;
private Long idx = new Long(0);
private Long applicationId;
private List<DfeApplicationOB> applications;
private List<LeasingProductOB> listLeasingProduct = new
ArrayList<LeasingProductOB>();
@Column(name = "NAZWA")
public String getNazwa() {
return nazwa;
}
public void setNazwa(String nazwa) {
this.nazwa = nazwa;
}
@Column(name = "IDX")
public Long getIdx() {
return idx;
}
public void setIdx(Long idx) {
this.idx = idx;
}
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@Cascade({ org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
@JoinColumn(name = "GROUPID", nullable = false)
public List<LeasingProductOB> getListLeasingProduct() {
return listLeasingProduct;
}
public void setListLeasingProduct(List<LeasingProductOB> listLeasingProduct) {
this.listLeasingProduct = listLeasingProduct;
}
@Column(name = "APPLICATIONID")
public Long getApplicationId() {
return applicationId;
}
public void setApplicationId(Long applicationId) {
this.applicationId = applicationId;
}
@JoinTable(name = "LEASINGPRODUCTGROUPAPP", joinColumns = {
@JoinColumn(name = "GROUPID", referencedColumnName = "ID", nullable = false) }, inverseJoinColumns = {
@JoinColumn(name = "APPID", referencedColumnName = "ID", nullable = false) })
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
public List<DfeApplicationOB> getApplications() {
return applications;
}
public void setApplications(List<DfeApplicationOB> applications) {
this.applications = applications;
}
}
DfeApplicationOB =数据库中的DFE_APPLICATION
当我尝试运行LeasingProductGroupOB.findByAppid时,我得到0个结果 有什么建议为什么或与查询不正确吗?谢谢。