根据孩子的身份查询

时间:2012-10-24 11:56:11

标签: java hibernate jpa

  

可能重复:
  How to write JPA query where parameter is a set?

我有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失败。我该如何解决?

1 个答案:

答案 0 :(得分:0)

尝试:SELECT con FROM Container con JOIN con.data ch WHERE ch = :child