【发布时间】:2017-09-28 19:39:24
【问题描述】:
我正在使用 H2-Database 和 Spring-Data PagingRepository。我喜欢使用分页并从数据库中选择所有 articles 字段 html 包含 '@' 或 '[at]' em> 或 '(at)' 或 'mail' ...
所以没有分页的原生查询看起来像
SELECT * FROM article WHERE (html LIKE '%@%' or html LIKE '%(at)%' or html LIKE '%[at]%' or ...)
我试着这样解决它:
Page<Article> findByHtmlContainingOrderByDateDesc(String[] string, Pageable pageable);
但是没有/空的结果。
我尝试的第二种方法是使用本机查询:
@Query(value = "SELECT * FROM article WHERE (html LIKE '%@%' or html LIKE '%(at)%') ORDER BY DATE desc \n#pageable\n" ,
nativeQuery = true,
countQuery = "SELECT count(*) FROM article WHERE (html LIKE '%@%' or html LIKE '%(at)%')")
Page<Article> findAll(@Param("pageable") Pageable pageable);
但我遇到了异常:
嵌套异常是 org.hibernate.exception.SQLGrammarException: could not prepare statement] 根本原因
非常感谢您的帮助!
【问题讨论】:
-
你看过stackoverflow.com/questions/38349930/… #pageable 魔法的依赖于 db 的变体。
标签: java sql spring-data h2