Java Jpql多线程连接
我们有两个实体:A和B A名单上有@OneToMany 两个实体都有日期 我们希望得到一个日期设置为null的实体,并用日期设置为null的B填充它Java Jpql多线程连接,java,hibernate,join,jpql,Java,Hibernate,Join,Jpql,我们有两个实体:A和B A名单上有@OneToMany 两个实体都有日期 我们希望得到一个日期设置为null的实体,并用日期设置为null的B填充它 @Query("select a from A a " + "left join a.bs b " + "on b.date is null " + "where a.date is null") 我们希望使用联接,因为对于以下请求,如果没有B,即使a有日期,也不会显示a @Query("select a from A a
@Query("select a from A a " +
"left join a.bs b " +
"on b.date is null " +
"where a.date is null")
我们希望使用联接,因为对于以下请求,如果没有B,即使a有日期,也不会显示a
@Query("select a from A a where a.date is null and a.bs.date is null").
下面是一组数据,用一个例子来解释
A B1 B2 Result
date not set Date not set Date not set no result
date not set Date not set Date set no result
date not set Date set Date not set no result
date not set Date set Date set no result
date set Date not set Date not set A only
date set Date set Date not set A with B1
date set Date not set Date set A with B2
date set Date set Date set A with B1 + B2
示例类:
public class A {
@Id
private Long id;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "bId")
private List<B> bs;
}
public class B {
@Id
private Long id;
}
公共A类{
@身份证
私人长id;
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
@JoinColumn(name=“投标”)
私人名单;
}
公共B级{
@身份证
私人长id;
}
太多了!:) 第二个查询应该是:
@Query("select a from A a where a.date is null and a.bs.date is null").
但很奇怪,你的例子和你的疑问不一致。。。
我会写下这样的话:
@Query("select a from A where a.date is not null and a.bs.date is not null")
您好,thx for your response,您对请求的权限,我编辑它,但是对于您的响应,如果a.bs.date为null且a.date不为null,则不会有结果。但是我们需要一个a为空的结果。换句话说,我需要JPQL中的这个SQL查询:SELECT*FROM a LEFT JOIN B B ON B.aId=a.id,B.date为null,其中a.date为null。