#java #postgresql #hibernate
#java #postgresql #гибернация
Вопрос:
Я получаю последнюю цену продукта следующим образом:
ProductPrice findFirstByProductIdOrderByDateFromDesc(@Param(value = "product") Long product);
Однако теперь я пытаюсь передать список идентификаторов продукта в качестве аргумента.
У меня есть следующее:
List<ProductPrice> findAllFirstByProductIdOrderByDateFromDesc(@Param(value = "product")List<Long> products);
Который при выполнении выдает:
2016-10-06 14:41:17,130 WARN o.h.e.j.s.SqlExceptionHelper: SQL Error: 0, SQLState: 42883
2016-10-06 14:41:17,130 ERROR o.h.e.j.s.SqlExceptionHelper: ERROR: operator does not exist: bigint = record
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Position: 7207
2016-10-06 14:41:17,148 ERROR o.a.c.c.C.[.[.[.[dispatcherServlet]: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause
org.postgresql.util.PSQLException: ERROR: operator does not exist: bigint = record
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Position: 7207
Есть идеи, что я делаю не так?
Ответ №1:
Попробуйте в
List<ProductPrice> findByProductIdInOrderByDateFromDesc(@Param(value = "product")List<Long> products);
Комментарии:
1. Это приведет к немного другому результату: мне нужна первая запись для каждой цены. Вот почему в исходном запросе у меня есть ‘findFirst …’
2. @uksz извините, но мне нужно было бы увидеть сопоставленные объекты, чтобы понять, чего вы пытаетесь достичь.