张志华 java_拼接HQL语句的时候出现类型转换异常 java.lang.ClassCastException

java.lang.ClassCastException:

java.lang.String cannot be cast to

com._520it.pss.domain.Employee

a4c26d1e5885305701be709a3d33442f.png

java.lang.ClassCastException:

java.lang.String cannot be cast to

com._520it.pss.domain.Employee

at

com._520it.pss.service.impl.EmployeeServiceImpl.queryForObject(EmployeeServiceImpl.java:49)

at

sun.reflect.NativeMethodAccessorImpl.invoke0(Native

Method)

at

sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at

sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at

java.lang.reflect.Method.invoke(Method.java:606)

at

org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)

at

org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)

at

org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)

at

org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)

at

org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)

at

org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)

at

org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)

at

org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)

at

org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)

at

org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)

at com.sun.proxy.$Proxy16.queryForObject(Unknown Source)

at

com._520it.test.TestService.testQueryForObject(TestService.java:63)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native

Method)

at

sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at

sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at

org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)

at

org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

at

org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)

at

org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

at

org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)

at

org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)

at

org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)

at

org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)

at

org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:254)

at

org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)

at

org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)

at

org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)

at

org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)

at

org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)

at

org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)

at

org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)

at

org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)

at

org.junit.runners.ParentRunner.run(ParentRunner.java:363)

at

org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)

at

org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

at

org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

at

org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

at

org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

at

org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

at

org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

原因总结:我在拼接HQL的时候,错误地以为是在拼接SQL,上述图片不需要加上那个.name,因为前面的obj要和后面的obj对应,如果需要查询某个类的具体属性,可以考虑使用原生SQL

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值