代码如下
String sql = "select t1.* from t_snow_call_mobile t1 LEFT JOIN t_snow_borrow_application t2 on t1.id_borrow_application = t2.id where t2.id_credit_user=@idUser order by t1.craw_time desc limit 0,1";
SqlTemplate sqlTemplate = new SqlTemplate(dao);
Map params = Maps.newHashMap("idUser",idUser);
CallMobile callMobile = sqlTemplate.queryForObject(sql, params,CallMobile.class);
我查询的明明是一个对象,但是,返回的时候只返回了一个id,结果报Long无法转换为CallMobile
异常如下:
For example:> "select t1.* from t_snow_call_mobile t1 LEFT JOIN t_snow_borrow_application t2 on t1.id_borrow_application = t2.id where t2.id_credit_user=71135 order by t1.craw_time desc limit 0,1"
org.nutz.castor.FailToCastObjectException: Fail to cast from <java.lang.Long> to <cn.xuezhongdai.bean.entity.antifraud.flow.CallMobile> for {38} because:
BorningException:Fail to born 'cn.xuezhongdai.bean.entity.antifraud.flow.CallMobile'
by args: [
@(38)] because: No suitable Constructor or Factory Method!!
at org.nutz.castor.Castors.cast(Castors.java:264)
at org.nutz.castor.Castors.castTo(Castors.java:318)
at org.nutz.dao.impl.sql.NutStatement.getObject(NutStatement.java:125)
at org.nutz.dao.impl.sql.SqlTemplate.queryForObject(SqlTemplate.java:237)
at org.nutz.dao.impl.sql.SqlTemplate.queryForObject(SqlTemplate.java:206)
at cn.xuezhongdai.dao.anti.impl.CallMobileDaoImpl.findLatest(CallMobileDaoImpl.java:33)
at cn.xuezhongdai.dao.anti.CallMobileDaoTest.findLatest(CallMobileDaoTest.java:30)
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:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
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:191)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
Caused by: org.nutz.lang.born.BorningException: Fail to born 'cn.xuezhongdai.bean.entity.antifraud.flow.CallMobile'
by args: [
@(38)] because: No suitable Constructor or Factory Method!!
at org.nutz.lang.Mirror.born(Mirror.java:988)
at org.nutz.castor.castor.Object2Object.cast(Object2Object.java:12)
at org.nutz.castor.Castors.cast(Castors.java:252)
... 34 more