简体   繁体   English

@Query 注解过滤数据

[英]@Query annotation to filter the data

I am facing issue in this below statement我在以下声明中面临问题

`SELECT b
FROM com.development.searchbooks.dto.BooksEntity b
WHERE lower(b.title) LIKE ?1
    OR lower(b.author_name) LIKE ?1
    OR lower(b.publication) LIKE ?1
ORDER BY title ASC LIMIT 10 OFFSET ?2`

unexpected token: LIMIT near line 1, column 173意外标记:第 1 行第 173 列附近的 LIMIT

This is the query i am using to filter based on keyword and order by ascending and doing pagination.这是我用来通过升序和分页根据关键字和顺序进行过滤的查询。 i am getting error right after adding "LIMIT 10 OFFSET?2" this POC.在添加“LIMIT 10 OFFSET?2”这个 POC 后,我得到了错误。

Kindly help on this.请帮助解决这个问题。

LIMIT keyword is not considered by jpa/jpql. jpa/jpql 不考虑 LIMIT 关键字。 So for using LIMIT with @Query, we cam make native query flag true.因此,为了将 LIMIT 与 @Query 一起使用,我们可以使本机查询标志为真。

( using - nativeQuery=true )

Below is the example下面是示例

@Query("SELECT s FROM Table s ORDER BY s.id DESC LIMIT 1", nativeQuery=true)

Finalized Answer for my Question,我的问题的最终答案,

@Query(value = "SELECT * FROM books WHERE lower(title) LIKE %?1% OR lower(author_name) LIKE %?1% OR lower(publication) LIKE %?1% ORDER BY title ASC LIMIT 10 OFFSET ?2", nativeQuery = true)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM