uksz uksz - 6 months ago 26
Java Question

Spring Data not executing query

I have an issue with query execution.

Here is my structure:


public class ProductPrice {
@GeneratedValue(strategy = GenerationType.SEQUENCE,
private long id;
private Float price;
private Date date_from;
private Product product;

Here is my ProductPriceDto

public class ProductPriceDto implements Serializable {
public Float price;
public Date date;

Here Is my PriceRepository

public interface PriceRepository extends CrudRepository<ProductPrice, Long> {
public static final String FIND_LAST_PRICE = "SELECT p.price, MAX(p.date_from) FROM ProductPrice p WHERE p.product = ?1 GROUP BY p.product";

ProductPriceDto findPrice(@Param(value = "product") Long product);

List<ProductPrice> findAll();

Now, when I am trying to execute
on PriceRepository, I am getting an error of:

java.lang.IllegalArgumentException: Parameter value [1] did not match
expected type [com.eternity.model.Product (n/a)]]

What am I doing wrong?


Despite good answers I've received from Wim, I decied to go with:

ProductPrice findFirstByProductIdOrderByDateFromDesc(@Param(value = "product") Long product);


Your query method expects a Long as the method argument, but in your JPQL query, you want a Product.

Change the query method argument to a Product.