2017-05-18 69 views
0

我有這樣的實體類:如何加入多個表中HQL

public class Work implements java.io.Serializable { 

private Integer workId; 
private User userByCreateBy; 
private User userByUpdateBy; 
private Long studyId; 
private String name; 
private byte panelType; 
private byte status; 
private Date createDate; 
private Date updateDate; 
private Set<Task> tasks = new HashSet<Task>(0); 

public Work() { 
} 

}

private Integer taskId; 
private User userByCompleteBy; 
private User userByExecutedBy; 
private Work work; 
private byte type; 
private Date startDate; 
private Date endDate; 
private byte status; 
private Date updateDate; 
private Forecast forecast; 
private Set<ForecastOutput> forecastOutputs = new HashSet<ForecastOutput>(0); 
private MonitorLottery monitorLottery; 
private QprMonitorLotteryArea qprMonitorLotteryArea; 
private Set<QprMonitorLotteryOutput> qprMonitorLotteryOutputs = new HashSet<QprMonitorLotteryOutput>(0); 
private Set<ForecastCellafter740> forecastCellafter740s = new HashSet<ForecastCellafter740>(0); 
private Set<QprMonitorLotteryResult> qprMonitorLotteryResults = new HashSet<QprMonitorLotteryResult>(0); 
private Set<AnswerDataOutput> answerDataOutputs = new HashSet<AnswerDataOutput>(0); 
private QprMonitorLottery qprMonitorLottery; 
private AnswerDataCheck answerDataCheck; 

public Task() { 
} 

}

公共類用戶實現java.io.Serializable {

private Integer userId; 
private String userName; 
private String password; 
private String name; 
private String email; 
private byte authority; 
private Date lastLogin; 
private Date passwordChangeDate; 
private byte status; 
private Integer createBy; 
private Integer updateBy; 
private Date createDate; 
private Date updateDate; 
private Set<MasterFile> masterFiles = new HashSet<MasterFile>(0); 
private Set<Task> tasksForCompleteBy = new HashSet<Task>(0); 
private Set<Work> worksForCreateBy = new HashSet<Work>(0); 
private Set<Work> worksForUpdateBy = new HashSet<Work>(0); 
private Set<Task> tasksForExecutedBy = new HashSet<Task>(0); 

public User() { 
} 

}

我想用HQL加入這個表,並得到用戶名,作品名稱,task.type,task.status等的細節。我已經做了這個代碼

StringBuilder dataQuery = new StringBuilder("select new com.web.main.view.WorkView(" 
     + "w.workId, " 
     + "w.studyId, " 
     + "w.name, " 
     + "w.panelType, " 
     + "t.type, " 
     + "t.status, " 
     + "u.user_name," 
     + "w.createDate, " 
     + "w.updateDate, " 
     + "t.startDate, "   
     + "t.endDate) " 
     + "from Work w left join w.tasks t left join w.user u where u.user_Id = w.create_by and w.status!=:status");  

但它給出的錯誤

HTTP狀態500 - 請求處理失敗;嵌套的例外是java.lang.IllegalArgumentException異常:org.hibernate.QueryException:無法解析屬性:用戶,

會有什麼問題我做錯了什麼

回答

0

在工作單位我沒有看到用戶字段 你有

private User userByCreateBy; 
private User userByUpdateBy; 

private User userByCompleteBy; 
private User userByExecutedBy; 

問題是在這條線

left join w.user u where u.user_Id = w.create_by 

你必須工作用戶列表,左連接同樣喜歡任務

+0

如何使用用戶列表進行更正。這個私人用戶userByCreateBy足夠加入對嗎? –

+0

如果你想要加入你需要一個像列表一樣的任務其他使用直接加入 – Ashish451

+0

我試着從工作中選擇計數(*)w左連接w.tasks t連接w.user你在哪裏w.status!=:狀態但它的結果出錯HTTP狀態500 - 請求處理失敗;嵌套的異常是java.lang.IllegalArgumentException:org.hibernate.QueryException:無法解析屬性:user –

1

Work實體上沒有名爲user的字段。因此,您應該用w.userByCreateByw.userByUpdateBy(或重命名實體字段)替換w.user