I need to get Entity1's by entity2's ids
There is params for query - List numbers - ids of entity2 . And two entities with @OneToMany bound
@Entity
class Entity1 {
private Integer id;
private Entity2 entity2;
---------
@OneToMany(cascade = ALL, fetch =FetchType.EAGER)
@Column
public Entity2 getEntity2(){
return entity2;
}
and
@Entity
public class Entity2{
private Integer id;
@ManyToOne(FetchType.LAZY)
private Entity1 entity1;
}
i have working code
@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);
}
i want beautify query by using Spring Data
and write something like
Set<Entity1> findAllByEntity2In(List<Integer> pChannels);
but it doesnt work now
I catch an Enxception :
\Caused by: java.lang.IllegalArgumentException: Parameter value element [2] did not match expected type [com.test.Entity2 (n/a)]
Who knows how to solve?
Thanks !