gpt4 book ai didi

java - 如何在HQL中连接多个表

转载 作者:行者123 更新时间:2023-12-02 13:09:01 24 4
gpt4 key购买 nike

我有这个实体类:

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() {
}

}

公共(public)类 User 实现 java.io.Serialized {

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 加入这个表并获取用户名、工作名、任务类型、任务状态等详细信息。我已经完成了这段代码

 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: 无法解析属性: user of,

如果我做错了什么,会出现什么问题

最佳答案

Work 实体上没有名为 user 的字段。因此,您应该将 w.user 替换为 w.userByCreateByw.userByUpdateBy (或重命名实体字段)。

关于java - 如何在HQL中连接多个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44039198/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com