我和其他人有同样的问题(未解决的问题)!当我使用 fetch('userWorkItems') 时,生成的 sql 查询将同时具有 LEFT OUTER JOIN 和 JOIN over TbUserWorkItem。我只需要在 TbUserWorkItem 表上进行左外连接!我该如何解决?
我的第一个模型:
@Entity
@Table(name = "TbWorkItem", schema = "mySchema")
public class TbWorkItem extends Model {
@Id
public Integer id;
public Integer code;
/* some other properties here */
@JsonIgnore
@OneToMany//(mappedBy = "workItem")
public List<TbUserWorkItem> userWorkItems;
public static Finder<Byte, TbWorkItem> find = new Finder(Byte.class, TbWorkItem.class);
public static List<TbWorkItem> all(Integer systemId, Integer workingUserId) {
/* return find
.fetch("userWorkItems")
.where()
.eq("system.id", systemId).eq("workItemInformationType.code", 1)
.or(
Expr.eq("publicWorkItemYesNo.code", 1),
Expr.and(Expr.eq("publicWorkItemYesNo.code", 2), Expr.eq("userWorkItems.workingUserId", workingUserId)))
.findList();
*/
return find
.where()
.eq("system.id", systemId).eq("workItemInformationType.code", 1)
.or(
Expr.eq("publicWorkItemYesNo.code", 1),
Expr.and(Expr.eq("publicWorkItemYesNo.code", 2), Expr.eq("userWorkItems.workingUserId", workingUserId)))
.findList();
}
}
和第二个模型:
@Entity
@Table(name="TbUserWorkItem",schema="mySchema")
public class TbUserWorkItem extends Model {
@Id
public Integer id;
/* some properties here */
@ManyToOne
@JoinColumn(name="WorkItemId")
public TbWorkItem workItem;
public static Finder<Integer,TbUserWorkItem> find=new Finder(Integer.class,TbUserWorkItem.class);
/*some methods here*/
}