我需要通过Entity2的ID来获取Entity1
有查询参数-列表编号-实体2的ID
。
和两个具有@OneToMany绑定的实体
@Entity
class Entity1 {
private Integer id;
private Entity2 entity2;
---------
@OneToMany(cascade = ALL, fetch =FetchType.EAGER)
@Column
public Entity2 getEntity2(){
return entity2;
}
和
@Entity
public class Entity2{
private Integer id;
@ManyToOne(FetchType.LAZY)
private Entity1 entity1;
}
我有工作代码
@Repository
public interface Entity1Repository extends JpaRepository<Entity1, Integer> {
@Query("SELECT c" +
" FROM Entity1 c" +
" inner JOIN c.entity2 a" +
" WHERE a.id IN(?1)")
Set<Entity1> findByEntity2Ids(List<Integer> pEntity2_Ids);
}
我想通过使用Spring Data美化查询
并写一些像
Set<Entity1> findAllByEntity2In(List<Integer> pChannels);
但现在不起作用
我陷入了困惑:
\原因:java.lang.IllegalArgumentException:参数值元素[2]与预期的类型[com.test.Entity2(n / a)]不匹配
谁知道如何解决?
谢谢 !
最佳答案
UPD
我发现了对Spring Data的查询:
@Repository
public interface Entity1Repository extends JpaRepository<Entity1, Integer> {
Set<Enity1> findByEntity2In(List<Integer> pEntities2Ids);
}