我有2个实体
@Entity
public class Container {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id;
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
Set<Child> data = newHashSet();
}
@Entity
public class Child {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id;
}
现在我要选择包含指定子项的所有容器。
我写了jpa查询select c from Container c where :child in c.data
,它产生了sql
select
container0_.id as id4_
from
Container container0_
cross join Container_Child data1_, Child child2_
where
container0_.id=data1_.Container_id
and data1_.data_id=child2_.id
and (? in (.))
limit ? [42001-168]
并以JdbcSQLException
失败。我该如何解决?
答案 0 :(得分:0)
尝试:SELECT con FROM Container con JOIN con.data ch WHERE ch = :child