0

I have a jpa query that holds two records, from the two records I am unable to select the first record using @query in jpql

Here is my snippet

@Query("select h from History h where h.id =:id and h.status =:status " +
            "and h.type =:type and h.user =:user")
    History getAHistory(@Param("id") Long id, @Param("status") Status status,
                                         @Param("type") Type type, @Param("user") User user);

From findings I am trying to use the LIMIT 1 but no success

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Blaze
  • 2,269
  • 11
  • 40
  • 82

1 Answers1

0

Your query returns a single History entity. If you plan to return more than one History entity you need to return a collection e.g. a list:

@Query("select h from History h where h.id = :id and h.status = :status " +
       "and h.type = :type and h.user = :user")
List<History> getAHistory(@Param("id") Long id, @Param("status") Status status,
                          @Param("type") Type type, @Param("user") User user);
Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
  • so list is the only way to tackle this – Blaze Mar 13 '20 at 18:04
  • It's one way to do it, or use a query and paramters that return just a single row. What is concerning that `id` parameter filtering returns more than one row. It's not a PK, so it's hard to tell what it is. – Karol Dowbecki Mar 13 '20 at 18:08