java—如何使用springjpa为本机sql查询设置偏移量和限制

mrfwxfqh  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(166)

我已经创建了一个从本地主机url获取偏移量和限制值的查询。但是我得到了下面的错误。

Hibernate: SELECT * FROM mail_user u  WHERE u.mailaddr LIKE ? AND u.userName LIKE ? AND u.sendflag =? AND (u.info01 LIKE ? OR u.info02 LIKE ? OR u.info03 LIKE ? OR u.info04 LIKE ? OR u.info05 LIKE ? ) ORDER BY u.userName ASC LIMIT ?
2018-08-30 12:58:47.905  WARN 9896 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 1064, SQLState: 42000
2018-08-30 12:58:47.905 ERROR 9896 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'null' at line 1
2018-08-30 12:58:47.909 DEBUG 9896 --- [nio-8080-exec-1] .m.m.a.ExceptionHandlerExceptionResolver : Resolving exception from handler [public java.util.List<usergroup.restapi.models.UserDetails> usergroup.restapi.controller.UserSearchController.getGroupList(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String)]: org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
2018-08-30 12:58:47.910 DEBUG 9896 --- [nio-8080-exec-1] .w.s.m.a.ResponseStatusExceptionResolver : Resolving exception from handler [public java.util.List<usergroup.restapi.models.UserDetails> usergroup.restapi.controller.UserSearchController.getGroupList(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String)]: org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
2018-08-30 12:58:47.911 DEBUG 9896 --- [nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolving exception from handler [public java.util.List<usergroup.restapi.models.UserDetails> usergroup.restapi.controller.UserSearchController.getGroupList(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String)]: org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
2018-08-30 12:58:47.916 DEBUG 9896 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Could not complete request

org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:242) ~[spring-orm-5.0.6.RELEASE.jar:5.0.6.RELEASE]
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:225) ~[spring-orm-5.0.6.RELEASE.jar:5.0.6.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:527) ~[spring-orm-5.0.6.RELEASE.jar:5.0.6.RELEASE]
    at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61) ~[spring-tx-5.0.6.RELEASE.jar:5.0.6.RELEASE]

我的本机sql查询如下:

@Query(
            value = "SELECT * FROM mail_user u  WHERE u.mailaddr LIKE %:mailaddr% AND u.userName LIKE %:userName% AND u.sendflag =:sendFlag AND "+"(u.info01 LIKE %:info01% OR u.info02 LIKE %:info02% OR u.info03 LIKE %:info03% OR u.info04 LIKE %:info04% OR u.info05 LIKE %:info05% )"+" ORDER BY u.userName ASC LIMIT :limit",nativeQuery = true
    )    public List<UserDetails> findByEmailAndUserAndFlag(@Param("mailaddr") String mailaddr,@Param("userName") String userName,@Param("sendFlag") String sendFlag,
            @Param("info01") String info01,@Param("info02") String info02,@Param("info03") String info03,@Param("info04") String info04,@Param("info05") String info05,
            @Param("limit") String limit
            );

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题