NutzCN Logo
问答 关于自增ID插入时出错的问题
发布于 2943天前 作者 老司机 2376 次浏览 复制 上一个帖子 下一个帖子
标签:

首先是bean

@Table("t_motherboardinfo")
public class MotherboardInfo {
	@Id
	int id;
	@Column
	String manufacturer;
	@Column
	String product_name;
	@Column
	String serial_number;
	@Column
	int nodeInfo_id;

这个按需求,一次会插入两条数据,这两条数据有时一样,有时不一样,当然id肯定不一样,当一样的时候就报错(因为测试环境没法产生出不一样的数据,所以没比较插入不一样会怎样),报错如下

    |        1 |           2 |           3 | 4 |
    |----------|-------------|-------------|---|
    | GIGABYTE | MD90-FS0-XX | FI4N6500089 | 0 |
  For example:> "INSERT INTO t_motherboardinfo(manufacturer,product_name,serial_number,nodeInfo_id) VALUES('GIGABYTE','MD90-FS0-XX','FI4N6500089',0) "
2016-11-01 10:09:15,342 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - RUN 
2016-11-01 10:09:15,342 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - INSERT INTO t_motherboardinfo(manufacturer,product_name,serial_number,nodeInfo_id) VALUES(?,?,?,?) 
    |        1 |           2 |           3 | 4 |
    |----------|-------------|-------------|---|
    | GIGABYTE | MD90-FS0-XX | FI4N6500089 | 0 |
  For example:> "INSERT INTO t_motherboardinfo(manufacturer,product_name,serial_number,nodeInfo_id) VALUES('GIGABYTE','MD90-FS0-XX','FI4N6500089',0) "
2016-11-01 10:09:15,343 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - RUN 
2016-11-01 10:09:15,344 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - RUN 
2016-11-01 10:09:15,345 org.nutz.lang.inject.InjectBySetter.inject(InjectBySetter.java:43) INFO  - Fail to value by setter
java.lang.IllegalArgumentException: object is not an instance of declaring class
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.nutz.lang.inject.InjectBySetter.inject(InjectBySetter.java:39)
	at org.nutz.dao.impl.entity.field.AbstractEntityField.setValue(AbstractEntityField.java:53)
	at org.nutz.dao.impl.entity.field.ManyLinkField$1.invoke(ManyLinkField.java:78)
	at org.nutz.lang.Lang.each(Lang.java:1551)
	at org.nutz.lang.Lang.each(Lang.java:1504)
	at org.nutz.dao.impl.entity.field.ManyLinkField.updateLinkedField(ManyLinkField.java:76)
	at org.nutz.dao.impl.link.DoInsertLinkVisitor$1.invoke(DoInsertLinkVisitor.java:29)
	at org.nutz.dao.impl.jdbc.NutPojo.onAfter(NutPojo.java:109)
	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:147)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithTransaction(NutDaoRunner.java:93)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:77)
	at org.nutz.dao.impl.sql.run.NutDaoRunner$1.run(NutDaoRunner.java:63)
	at org.nutz.trans.Trans.exec(Trans.java:174)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:61)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:266)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:274)
	at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:50)
	at org.nutz.dao.impl.NutDao.insertWith(NutDao.java:230)
	at com.amax.dao.EntityDao.insertNodeInfo(EntityDao.java:74)
	at com.amax.service.EntityService.getNodeInfo2(EntityService.java:219)
	at com.amax.module.EntityModule.getNodeInfo(EntityModule.java:36)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:25)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:198)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)
2016-11-01 10:09:15,353 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) WARN  - Error@/entity/node_info :
org.nutz.dao.DaoException: java.lang.RuntimeException: Fail to set '13'[ 13 ] by setter com.amax.bean.MotherboardInfo.'setId()' because [java.lang.IllegalArgumentException: object is not an instance of declaring class]: object is not an instance of declaring class
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithTransaction(NutDaoRunner.java:104)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:77)
	at org.nutz.dao.impl.sql.run.NutDaoRunner$1.run(NutDaoRunner.java:63)
	at org.nutz.trans.Trans.exec(Trans.java:174)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:61)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:266)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:274)
	at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:50)
	at org.nutz.dao.impl.NutDao.insertWith(NutDao.java:230)
	at com.amax.dao.EntityDao.insertNodeInfo(EntityDao.java:74)
	at com.amax.service.EntityService.getNodeInfo2(EntityService.java:219)
	at com.amax.module.EntityModule.getNodeInfo(EntityModule.java:36)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:25)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:198)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: Fail to set '13'[ 13 ] by setter com.amax.bean.MotherboardInfo.'setId()' because [java.lang.IllegalArgumentException: object is not an instance of declaring class]: object is not an instance of declaring class
	at org.nutz.lang.Lang.makeThrow(Lang.java:133)
	at org.nutz.lang.inject.InjectBySetter.inject(InjectBySetter.java:44)
	at org.nutz.dao.impl.entity.field.AbstractEntityField.setValue(AbstractEntityField.java:53)
	at org.nutz.dao.impl.entity.field.ManyLinkField$1.invoke(ManyLinkField.java:78)
	at org.nutz.lang.Lang.each(Lang.java:1551)
	at org.nutz.lang.Lang.each(Lang.java:1504)
	at org.nutz.dao.impl.entity.field.ManyLinkField.updateLinkedField(ManyLinkField.java:76)
	at org.nutz.dao.impl.link.DoInsertLinkVisitor$1.invoke(DoInsertLinkVisitor.java:29)
	at org.nutz.dao.impl.jdbc.NutPojo.onAfter(NutPojo.java:109)
	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:147)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithTransaction(NutDaoRunner.java:93)
	... 49 more

这个意思是第一条插入,第二条有问题???

14 回复
at com.amax.dao.EntityDao.insertNodeInfo(EntityDao.java:74)

这部分的代码贴出来看看, 看上去是插入关联关系的时候报错

这个dao方法很简单

public void insertNodeInfo(NodeInfo nodeInfo) {
		dao.insertWith(nodeInfo, "cpus|memorys|pcies|fans|powers|usbs|bios|motherboards|mvcs");
	}

再帖一下,nodeinfo类

@Table("t_nodeInfo")
public class NodeInfo {
	@Id
	int id;
	@Column
	int entity_id;
	@Column
	Date record_time;
	@Column
	@ColDefine(width = 200)
	String osInfo;
	@Column
	@ColDefine(width = 200)
	String diskInfo;
	@Many(target = CPUInfo.class, field = "id")
	ArrayList<CPUInfo> cpus;
	@Many(target = MemoryInfo.class, field = "id")
	ArrayList<MemoryInfo> memorys;
	@Many(target = PCIeInfo.class, field = "id")
	ArrayList<PCIeInfo> pcies;
	@Many(target = FanInfo.class, field = "id")
	ArrayList<FanInfo> fans;
	@Many(target = PowerInfo.class, field = "id")
	ArrayList<PowerInfo> powers;
	@Many(target = USBInfo.class, field = "id")
	ArrayList<USBInfo> usbs;
	@Many(target = BiosInfo.class, field = "id")
	ArrayList<BiosInfo> bios;
	@Many(target = MotherboardInfo.class, field = "id")
	ArrayList<MotherboardInfo> motherboards;
	@Many(target = MotherboardInfo.class, field = "id")
	ArrayList<MVCInfo> mvcs;

@wendal 问题好像是field,field应该是子类指向母类的字段吧,就是应该改成nodeinfo_id?就是第一个bean的外联字段?
但改过来后她还是报错:

    |        1 |           2 |           3 |  4 |
    |----------|-------------|-------------|----|
    | GIGABYTE | MD90-FS0-XX | FI4N6500089 | 14 |
  For example:> "INSERT INTO t_motherboardinfo(manufacturer,product_name,serial_number,nodeInfo_id) VALUES('GIGABYTE','MD90-FS0-XX','FI4N6500089',14) "
2016-11-01 10:26:53,320 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - RUN 
2016-11-01 10:26:53,320 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - INSERT INTO t_motherboardinfo(manufacturer,product_name,serial_number,nodeInfo_id) VALUES(?,?,?,?) 
    |        1 |           2 |           3 |  4 |
    |----------|-------------|-------------|----|
    | GIGABYTE | MD90-FS0-XX | FI4N6500089 | 14 |
  For example:> "INSERT INTO t_motherboardinfo(manufacturer,product_name,serial_number,nodeInfo_id) VALUES('GIGABYTE','MD90-FS0-XX','FI4N6500089',14) "
2016-11-01 10:26:53,321 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - RUN 
2016-11-01 10:26:53,321 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - RUN 
2016-11-01 10:26:53,323 org.nutz.lang.inject.InjectBySetter.inject(InjectBySetter.java:43) INFO  - Fail to value by setter
java.lang.IllegalArgumentException: object is not an instance of declaring class
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.nutz.lang.inject.InjectBySetter.inject(InjectBySetter.java:39)
	at org.nutz.dao.impl.entity.field.AbstractEntityField.setValue(AbstractEntityField.java:53)
	at org.nutz.dao.impl.entity.field.ManyLinkField$1.invoke(ManyLinkField.java:78)
	at org.nutz.lang.Lang.each(Lang.java:1551)
	at org.nutz.lang.Lang.each(Lang.java:1504)
	at org.nutz.dao.impl.entity.field.ManyLinkField.updateLinkedField(ManyLinkField.java:76)
	at org.nutz.dao.impl.link.DoInsertLinkVisitor$1.invoke(DoInsertLinkVisitor.java:29)
	at org.nutz.dao.impl.jdbc.NutPojo.onAfter(NutPojo.java:109)
	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:147)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithTransaction(NutDaoRunner.java:93)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:77)
	at org.nutz.dao.impl.sql.run.NutDaoRunner$1.run(NutDaoRunner.java:63)
	at org.nutz.trans.Trans.exec(Trans.java:174)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:61)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:266)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:274)
	at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:50)
	at org.nutz.dao.impl.NutDao.insertWith(NutDao.java:230)
	at com.amax.dao.EntityDao.insertNodeInfo(EntityDao.java:74)
	at com.amax.service.EntityService.getNodeInfo2(EntityService.java:219)
	at com.amax.module.EntityModule.getNodeInfo(EntityModule.java:36)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:25)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:198)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)
2016-11-01 10:26:53,330 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) WARN  - Error@/entity/node_info :
org.nutz.dao.DaoException: java.lang.RuntimeException: Fail to set '14'[ 14 ] by setter com.amax.bean.MotherboardInfo.'setNodeInfo_id()' because [java.lang.IllegalArgumentException: object is not an instance of declaring class]: object is not an instance of declaring class
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithTransaction(NutDaoRunner.java:104)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:77)
	at org.nutz.dao.impl.sql.run.NutDaoRunner$1.run(NutDaoRunner.java:63)
	at org.nutz.trans.Trans.exec(Trans.java:174)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:61)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:266)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:274)
	at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:50)
	at org.nutz.dao.impl.NutDao.insertWith(NutDao.java:230)
	at com.amax.dao.EntityDao.insertNodeInfo(EntityDao.java:74)
	at com.amax.service.EntityService.getNodeInfo2(EntityService.java:219)
	at com.amax.module.EntityModule.getNodeInfo(EntityModule.java:36)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:25)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:198)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: Fail to set '14'[ 14 ] by setter com.amax.bean.MotherboardInfo.'setNodeInfo_id()' because [java.lang.IllegalArgumentException: object is not an instance of declaring class]: object is not an instance of declaring class
	at org.nutz.lang.Lang.makeThrow(Lang.java:133)
	at org.nutz.lang.inject.InjectBySetter.inject(InjectBySetter.java:44)
	at org.nutz.dao.impl.entity.field.AbstractEntityField.setValue(AbstractEntityField.java:53)
	at org.nutz.dao.impl.entity.field.ManyLinkField$1.invoke(ManyLinkField.java:78)
	at org.nutz.lang.Lang.each(Lang.java:1551)
	at org.nutz.lang.Lang.each(Lang.java:1504)
	at org.nutz.dao.impl.entity.field.ManyLinkField.updateLinkedField(ManyLinkField.java:76)
	at org.nutz.dao.impl.link.DoInsertLinkVisitor$1.invoke(DoInsertLinkVisitor.java:29)
	at org.nutz.dao.impl.jdbc.NutPojo.onAfter(NutPojo.java:109)
	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:147)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithTransaction(NutDaoRunner.java:93)
	... 49 more

整个MotherboardInfo贴一下,包括setter和getter

@wendal
整个bean

package com.amax.bean;

import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Id;
import org.nutz.dao.entity.annotation.Table;

@Table("t_motherboardinfo")
public class MotherboardInfo {
	@Id
	int id;
	@Column
	String manufacturer;
	@Column
	String product_name;
	@Column
	String serial_number;
	@Column
	int nodeInfo_id;

	public String getManufacturer() {
		return manufacturer;
	}

	public void setManufacturer(String manufacturer) {
		this.manufacturer = manufacturer;
	}

	public String getProduct_name() {
		return product_name;
	}

	public void setProduct_name(String product_name) {
		this.product_name = product_name;
	}

	public String getSerial_number() {
		return serial_number;
	}

	public void setSerial_number(String serial_number) {
		this.serial_number = serial_number;
	}

	public int getNodeInfo_id() {
		return nodeInfo_id;
	}

	public void setNodeInfo_id(int nodeInfo_id) {
		this.nodeInfo_id = nodeInfo_id;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
}

在InjectBySetter的42行打断点,看看obj是什么

不好插图片,非常奇怪, setter.invoke(obj, v);里的obj竟然是一个MVCInfo的实体类(也是nodeinfo下面的一个子类),name和value是我想要的值,但是id和nodeInfo_id,是零!

知道了

	@Many(target = MotherboardInfo.class, field = "id")
	ArrayList<MotherboardInfo> motherboards;
	@Many(target = MotherboardInfo.class, field = "id")
	ArrayList<MVCInfo> mvcs;

mvcs的@Many的target配置错了

@wendal 丢脸丢大发了,不过这个真不好找,这还是上个星期写的,估计加班加的眼花了,还是能希望报错再智能点,能别顺藤摸错瓜

没事,这个地方应该自动推导的

@wendal nutz是否提供这样一个方法,两个同类型实体类,如果键值对都一样就认定相等,object.equals,并没有这个功能

@qq_c1bab051

Lang.equals(Lang.obj2map(objA), Lang.obj2map(objB));

@wendal

List<NodeInfo> nodeInfos = dao.query(NodeInfo.class, Cnd.where("storage", "=", "false"));
		for (NodeInfo nodeInfo : nodeInfos) {
			dao.deleteWith(nodeInfo, null);
		}

debug发现,nodeinfo的关联字段名没有赋值全是null,导致并没有删掉关联记录,求解决办法

@qq_c1bab051 用clearLinks

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