Closed yuxicun closed 5 years ago
@yuxicun 不太懂你的意思,把代码和参数变量写全,where
和 1=1
这些边界需要自己控制。
抱歉,不知道为什么,我贴入代码后,这个编辑器把代码给移除了,我还发现一个问题 当我只写:from Test as b ... 就是前面不加select b的时候加入分页会报错,不加分页正常
Hibernate: select test0_.id as id16, test0_.create_date as create_d26, test0_.last_modify_date as last_mod36, test0_.birth as birth46, test0_.content as content56, test0_.mark as mark66, test0_.name as name76, test0_.title as title86 from test test0 where 1=1 and (test0.name like ?) limit ?
2019-11-09 23:24:10.473 TRACE 5344 --- [p-nio-80-exec-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] - [%1%]
2019-11-09 23:24:10.505 DEBUG 5344 --- [p-nio-80-exec-1] .m.m.a.ExceptionHandlerExceptionResolver : Using @ExceptionHandler com.scy.web.common.exception.GlobalExceptionHandler#handleException(HttpServletRequest, Exception)
2019-11-09 23:24:10.505 TRACE 5344 --- [p-nio-80-exec-1] .w.s.m.m.a.ServletInvocableHandlerMethod : Arguments: [org.apache.shiro.web.servlet.ShiroHttpServletRequest@47e2ffb, org.springframework.dao.InvalidDataAccessApiUsageException: Type specified for TypedQuery [java.lang.Long] is incompatible with query return type [class com.scy.web.api.entity.Test]; nested exception is java.lang.IllegalArgumentException: Type specified for TypedQuery [java.lang.Long] is incompatible with query return type [class com.scy.web.api.entity.Test]]
org.springframework.dao.InvalidDataAccessApiUsageException: Type specified for TypedQuery [java.lang.Long] is incompatible with query return type [class com.scy.web.api.entity.Test]; nested exception is java.lang.IllegalArgumentException: Type specified for TypedQuery [java.lang.Long] is incompatible with query return type [class com.scy.web.api.entity.Test]
at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:374)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:257)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:528)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:153)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:149)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy154.queryMyTests(Unknown Source)
at com.scy.web.api.service.impl.TestServiceImpl.queryMyTests(TestServiceImpl.java:96)
at com.scy.web.api.service.impl.TestServiceImpl$$FastClassBySpringCGLIB$$e9bd234e.invoke(
Pageable pageable = PageRequest.of(0, 3, Sort.by(Sort.Order.desc("createDate"))); 这么写是正常的
Pageable pageable = PageRequest.of(0, 1, Sort.by(Sort.Order.desc("createDate"))); 这么写,就会报错,不知道啥原因,当xml中的hql语言 不加select b 这种语句,而直接使用from Test的时候
这段代码,当in的有值,name也有值的情况下,缺失and报错
这段代码,当in没有值,name有值时,发生and报错