Answer the question
In order to leave comments, you need to log in
Spring Data Jpa @Query error?
I have two entities:
public class DiscountsEntity implements Serializable {
private Integer id;
private Integer discount;
@ManyToOne(fetch = FetchType.LAZY, cascade=CascadeType.ALL)
@JoinColumn(name = "id_item", nullable = false)
private ItemEntity id_item;
....
public class ItemEntity implements Serializable {
private Integer id;
@NotNull
private Integer price;
@NotEmpty
private String name;
@OneToMany
@JoinColumn(name="id")
private List<ItemEntity> id_item;
...
public interface DiscountsEntityRepository extends JpaRepository<DiscountsEntity, Integer> {
//@Query("select d.discount from DiscountsEntity d where d.id_item = :id")
//DiscountsEntity findById_Item(@Param("id") Integer id);
//@Query("select d from DiscountsEntity d where d.id_item = :item")
//DiscountsEntity findById_item(@Param("item") ItemEntity item);
//@QueryHints(value = {@QueryHint(name = "name", value = "value")})
//Page<DiscountsEntity> findById_item(ItemEntity id_item);
//DiscountsEntity findById_item_Id(Integer id_item_Id);
//List<DiscountsEntity> findById_item(ItemEntity id_item);
//@Query("select d.discount from DiscountsEntity d where d.id_item = ?1")
//List<DiscountsEntity> findById_item(Integer id_item);
@Query("select d from DiscountsEntity d where d.id_item = :id_item")
DiscountsEntity findById_item_Id(Integer id_item);
}
HTTP Status 500 - Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.QueryParameterException: Position beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based! Position: 1; nested exception is java.lang.IllegalArgumentException: org.hibernate.QueryParameterException: Position beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based! Position: 1
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question