我有一个包含两条记录的 jpa 查询,从这两条记录中我无法使用 jpql 中的 @query 选择第一条记录
这是我的片段
@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);
根据调查结果,我尝试使用 LIMIT 1 但没有成功
最佳答案
您的查询返回单个History
实体。如果您计划返回多个 History
实体,则需要返回一个集合,例如列表:
@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);
关于java - 在jpa中使用@query选择第一条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60675165/