spring-data-jpa @Query支持正则表达式语法?

时间:2014-05-19 06:22:57

标签: mysql spring-data spring-data-jpa

我现在使用spring数据jpa连接 MySQL 服务器,如何使用@Query设置正则表达式搜索?

@Query(value = "select t from Tenants t where t.id regexp ?1")
Page regexSearch(String text, Pageable pageable);

我的代码不起作用,错误是“引起:org.hibernate.hql.internal.ast.QuerySyntaxException:意外令牌:regexp靠近第1行,第72列[从com.sg.beans中选择t。租户t.id regexp?1] “,有没有人知道怎么写正则表达式搜索?

1 个答案:

答案 0 :(得分:1)

JPQL不支持正则表达式功能。您需要回退到本机SQL(使用nativeQuery注释上的@Query标记。)