NutzCN Logo
问答 偶尔出现错误cannot be cast to
发布于 2737天前 作者 撒哈拉来的企鹅 4686 次浏览 复制 上一个帖子 下一个帖子
标签:

在insert或者fetch的时候有时会出现错误:Fail to set '4t9ceejnmihh4p9rrpabav7bq0'[ 4t9ceejnmihh4p9rrpabav7bq0 ] by setter cn.loyle.mybaby.pojo.User.'setId()' because [java.lang.ClassCastException: cn.loyle.mybaby.pojo.User cannot be cast to cn.loyle.mybaby.pojo.User]: cn.loyle.mybaby.pojo.User cannot be cast to cn.loyle.mybaby.pojo.User

User的id属性为
@Name
@Prev(els=@EL("uuid(32)"))
private String id;

8 回复

开发时? 生产环境??

完整报错信息贴一下.

回复按钮旁边有插入代码的按钮!!

java.lang.ClassCastException: cn.loyle.mybaby.pojo.User cannot be cast to cn.loyle.mybaby.pojo.User
	at cn.loyle.mybaby.pojo.User$FM$setId$ab706b0cf40b3b24094a0af312e173b9.invoke(User.java)
	at org.nutz.lang.inject.InjectBySetter.inject(InjectBySetter.java:47)
	at org.nutz.dao.impl.entity.field.AbstractEntityField.setValue(AbstractEntityField.java:53)
	at org.nutz.dao.impl.entity.macro.ElFieldMacro.onAfter(ElFieldMacro.java:43)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:64)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66)
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:158)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithTransaction(NutDaoRunner.java:104)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:88)
	at org.nutz.dao.impl.sql.run.NutDaoRunner$1.run(NutDaoRunner.java:74)
	at org.nutz.trans.Trans.exec(Trans.java:174)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:72)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:245)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:257)
	at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:55)
	at org.nutz.dao.impl.NutDao.insert(NutDao.java:105)
	at cn.loyle.mybaby.dao.Dao.addUser(Dao.java:32)
	at cn.loyle.mybaby.service.UserService.init(UserService.java:19)
	at cn.loyle.mybaby.controller.AdminHomeController.login(AdminHomeController.java:28)
	at cn.loyle.mybaby.controller.AdminHomeControllerMethodAccess.invoke(Unknown Source)
	at act.handler.builtin.controller.impl.ReflectedHandlerInvoker.invoke(ReflectedHandlerInvoker.java:572)
	at act.handler.builtin.controller.impl.ReflectedHandlerInvoker.handle(ReflectedHandlerInvoker.java:267)
	at act.handler.builtin.controller.ControllerAction.handle(ControllerAction.java:51)
	at act.handler.builtin.controller.RequestHandlerProxy._handle(RequestHandlerProxy.java:466)
	at act.handler.builtin.controller.RequestHandlerProxy.handle(RequestHandlerProxy.java:185)
	at act.handler.DelegateRequestHandler.handle(DelegateRequestHandler.java:47)
	at act.route.Router$ContextualHandler.handle(Router.java:1288)
	at act.xio.NetworkHandler$1.run(NetworkHandler.java:136)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
19:30:27.942 [XNIO-1 task-13] ERROR a.h.b.c.RequestHandlerProxy - Error handling request
org.nutz.dao.DaoException: java.lang.RuntimeException: Fail to set '4t9ceejnmihh4p9rrpabav7bq0'[ 4t9ceejnmihh4p9rrpabav7bq0 ] by setter cn.loyle.mybaby.pojo.User.'setId()' because [java.lang.ClassCastException: cn.loyle.mybaby.pojo.User cannot be cast to cn.loyle.mybaby.pojo.User]: cn.loyle.mybaby.pojo.User cannot be cast to cn.loyle.mybaby.pojo.User
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithTransaction(NutDaoRunner.java:115)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:88)
	at org.nutz.dao.impl.sql.run.NutDaoRunner$1.run(NutDaoRunner.java:74)
	at org.nutz.trans.Trans.exec(Trans.java:174)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:72)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:245)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:257)
	at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:55)
	at org.nutz.dao.impl.NutDao.insert(NutDao.java:105)
	at cn.loyle.mybaby.dao.Dao.addUser(Dao.java:32)
	at cn.loyle.mybaby.service.UserService.init(UserService.java:19)
	at cn.loyle.mybaby.controller.AdminHomeController.login(AdminHomeController.java:28)
	at cn.loyle.mybaby.controller.AdminHomeControllerMethodAccess.invoke(Unknown Source)
	at act.handler.builtin.controller.impl.ReflectedHandlerInvoker.invoke(ReflectedHandlerInvoker.java:572)
	at act.handler.builtin.controller.impl.ReflectedHandlerInvoker.handle(ReflectedHandlerInvoker.java:267)
	at act.handler.builtin.controller.ControllerAction.handle(ControllerAction.java:51)
	at act.handler.builtin.controller.RequestHandlerProxy._handle(RequestHandlerProxy.java:466)
	at act.handler.builtin.controller.RequestHandlerProxy.handle(RequestHandlerProxy.java:185)
	at act.handler.DelegateRequestHandler.handle(DelegateRequestHandler.java:47)
	at act.route.Router$ContextualHandler.handle(Router.java:1288)
	at act.xio.NetworkHandler$1.run(NetworkHandler.java:136)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: Fail to set '4t9ceejnmihh4p9rrpabav7bq0'[ 4t9ceejnmihh4p9rrpabav7bq0 ] by setter cn.loyle.mybaby.pojo.User.'setId()' because [java.lang.ClassCastException: cn.loyle.mybaby.pojo.User cannot be cast to cn.loyle.mybaby.pojo.User]: cn.loyle.mybaby.pojo.User cannot be cast to cn.loyle.mybaby.pojo.User
	at org.nutz.lang.Lang.wrapThrow(Lang.java:167)
	at org.nutz.lang.inject.InjectBySetter.inject(InjectBySetter.java:58)
	at org.nutz.dao.impl.entity.field.AbstractEntityField.setValue(AbstractEntityField.java:53)
	at org.nutz.dao.impl.entity.macro.ElFieldMacro.onAfter(ElFieldMacro.java:43)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:64)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66)
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:158)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithTransaction(NutDaoRunner.java:104)
	... 23 common frames omitted
Caused by: java.lang.ClassCastException: cn.loyle.mybaby.pojo.User cannot be cast to cn.loyle.mybaby.pojo.User
	at cn.loyle.mybaby.pojo.User$FM$setId$ab706b0cf40b3b24094a0af312e173b9.invoke(User.java)
	at org.nutz.lang.inject.InjectBySetter.inject(InjectBySetter.java:47)
	... 32 common frames omitted

看上去是reload过,但老的classloader加载的类,所对应的FastClass类没有更新

可以考虑关掉FastClass,通过NutConf的开关可以做到

是不是因为热加载的问题,如果到生产环境的话应该就没问题了吧

@qq_a6eec308 应该是的,开发期禁用FastClass就好了

添加回复
请先登陆
回到顶部