我在Hibernate.Say報表和項目表中有一對多關係。一個報表有很多項目和項目可以處於活動或不活動狀態。需要使用Active項目獲取所有報告。一對多將填補所有的子記錄忽略條件中的條件
Class Report{
@OneToMany(mappedby="reports")
List<Projects> projList;
/*get and set methods */
}
Class Project{
@ManyToOne
Report repors;
/*get and set methods */
/*This is a column which represenst ACTIVE or NOT*/
private status;
}
我試圖把所有與活動項目的報告,我的標準是這樣的:
List<Reports> reportsList = Criteria(Reports.class)
.createAlias("projList","projList",INNER_JOIN)
.add(Restrictions.eq("projList.status","ACTIVE")).list()
當我遍歷了reportsList並獲得相應的項目它返回我所有的項目與ACTIVE或INACTIVE無關。
for(Report rep:reportsList){
rep.getProjList();
//This is returning me all the projects irresective of my criteria for
// ACTIVE projects. This is hitting another query to the table with the report id
//only but not with the status= ACTIVE.So this is returning me all the Projects.
}
但是,當我做一個左外部連接,而不是內部連接,我收到正確的結果,即只有ACTIVE項目。我不知道爲什麼?
你能解釋我是如何,它是否正確,它會在所有情況下consitent? 或我應該加載活動項目,並獲得相應的報告對項目具有 即標準(從子到父)
只是一個筆記狀態數據類型丟失。 –