Mam dwie encje:
@Entity
public class FirstEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
@Size(min = 1, max = 50)
private String title;
@Column(nullable = true)
private String description;
@OneToMany(mappedBy = "firstEntity")
private Set<SecondEntity> secondEntities = new HashSet<>();
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Set<SecondEntity> getSecondEntities() {
return secondEntities;
}
public void setSecondEntities(Set<SecondEntity> secondEntities) {
this.secondEntities = secondEntities;
}
}
@Entity
public class SecondEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
private FirstEntity firstEntity;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public FirstEntity getFirstEntity() {
return firstEntity;
}
public void setFirstEntity(FirstEntity firstEntity) {
this.firstEntity = firstEntity;
}
}
Mam tez repozytorium
@Repository
public interface FirstRepository extends JpaRepository<FirstEntity, Long>,
JpaSpecificationExecutor<FirstEntity> {
@Query("SELECT e.id, e.title, COUNT(*) " +
"FROM myPackage.FirstEntity e " +
"LEFT JOIN e.secondEntities " +
"GROUP BY e.id, e.title")
List<Object[]> getData();
}
Chciałbym filtrować dane za pomocą specyfikacji. Przerobiłem więc powyższy kod:
@Repository
public interface FirstRepository extends JpaRepository<FirstEntity, Long>,
JpaSpecificationExecutor<FirstEntity> {
@Query("SELECT e.id, e.title, COUNT(*) " +
"FROM myPackage.FirstEntity e " +
"LEFT JOIN e.secondEntities " +
"GROUP BY e.id, e.title")
List<Object[]> getData(Specifications<FirstEntity> specifications);
}
Po wywołaniu metody getData dostaje wyjątek: java.lang.IllegalArgumentException: Parameter with that position [1] did not exist
Czy istnieje jakis sposób na to aby połączyć zapytania JPQL ze specyfikacjami?