NutzCN Logo
问答 用fetchx查询报错(对象是复合建)
发布于 3278天前 作者 fwm520 3472 次浏览 复制 上一个帖子 下一个帖子
标签: dao

org.nutz.dao.DaoException: java.util.NoSuchElementException
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:76)
at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:199)
at org.nutz.dao.impl.NutDao.fetchx(NutDao.java:484)
at com.hdkg.service.StoreHouseService.delShosp(StoreHouseService.java:159)
at com.hdkg.module.StoreHouseModule.del(StoreHouseModule.java:77)
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:22)
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:40)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:99)
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:40)
at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:64)
at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:94)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
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.util.NoSuchElementException
at java.util.ArrayList$Itr.next(Unknown Source)
at org.nutz.dao.impl.sql.pojo.PkConditionPItem.joinSql(PkConditionPItem.java:25)
at org.nutz.dao.impl.jdbc.NutPojo.toPreparedStatement(NutPojo.java:97)
at org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:175)
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:43)
at org.nutz.dao.impl.DaoSupport$DaoExec.invoke(DaoSupport.java:244)
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:64)
... 40 more

以上就是后台报错

StoreHouseOfShopProd shosp = getDao().fetchx(StoreHouseOfShopProd.class, storeHouseId, prodId);
这是查询句

@Table("storehouse_shop_prod")
@PK({"storehouseId", "shopProdId"})
public class StoreHouseOfShopProd {

@Column("shop_product_id")
private Long shopProdId;

@Column("storehouse_id")
private int storehouseId;

这是对象的复合键

15 回复

@PK 是刚加的? 没编译吧

@PK一直都在啊,不过还是报这个错误

我测试一下, 正常,代码如下

package net.wendal.nutzbook.bean.demo;

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

@PK({"pkA", "pkB"})
@Table("t_demo_test_pks")
public class BeanHasPK {

	@Column("pka")
	private String pkA;
	@Column("pkb")
	private String pkB;
	public String getPkA() {
		return pkA;
	}
	public void setPkA(String pkA) {
		this.pkA = pkA;
	}
	public String getPkB() {
		return pkB;
	}
	public void setPkB(String pkB) {
		this.pkB = pkB;
	}
}

查询代码

// 测试@PK
dao.create(BeanHasPK.class, true);// 删表重建,方便测试
dao.fetchx(BeanHasPK.class, "abc", "wendal"); // 查询多主键

日志输出

2015-11-10 11:15:43,665 org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:313) DEBUG - DROP TABLE t_demo_test_pks
2015-11-10 11:15:43,709 org.nutz.dao.impl.jdbc.AbstractJdbcExpert.setupEntityField(AbstractJdbcExpert.java:102) DEBUG - Table 't_demo_test_pks' doesn't exist!
2015-11-10 11:15:43,710 org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:313) DEBUG - CREATE TABLE t_demo_test_pks(
pka VARCHAR(50),
pkb VARCHAR(50),
PRIMARY KEY (pka,pkb)
) ENGINE=InnoDB CHARSET=utf8
2015-11-10 11:15:43,777 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:212) DEBUG - SELECT * FROM t_demo_test_pks  WHERE pka=? AND pkb=? 
    |   1 |      2 |
    |-----|--------|
    | abc | wendal |
  For example:> "SELECT * FROM t_demo_test_pks  WHERE pka='abc' AND pkb='wendal' "

@wendal 教授,你经验丰富,能知道我这种情况大概是什么原因造成的吗?复合键和参数位置都一致啊,我想不出哪里出错了

@fwm520 拿我的代码测试

@wendal 活见鬼了,你的代码可以,最吐血的是我没发现我的跟教授你那个代码有什么区别。。。。。。。

其他属性你没写出来吧? 整个类就2个属性??

或者是import错了

@fwm520 把你的代码贴完整一点。。

@wendal 好的

import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.One;
import org.nutz.dao.entity.annotation.PK;
import org.nutz.dao.entity.annotation.Table;

/**
* 仓库表
*/
@PK({"storehouseId","shopProdId"})
@Table("storehouse_shop_prod")

public class StoreHouseOfShopProd {

@Column("shop_product_id")
private long shopProdId;

@Column("storehouse_id")
private int storehouseId;

@Column("stock")
private Integer stock;

@Column("remarks")
private String remarks;

@One(target = StoreHouse.class, field = "id", key = "storehouseId")

getset方法我就不列出来了

用了你的类,去掉了@One之后测试代码及日志输出, 很正常的

dao.create(StoreHouseOfShopProd.class, true);
dao.fetchx(BeanHasPK.class, 1, 2);
2015-11-10 15:32:33,580 org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:313) DEBUG - DROP TABLE storehouse_shop_prod
2015-11-10 15:32:33,599 org.nutz.dao.impl.jdbc.AbstractJdbcExpert.setupEntityField(AbstractJdbcExpert.java:102) DEBUG - Table 'storehouse_shop_prod' doesn't exist!
2015-11-10 15:32:33,600 org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:313) DEBUG - CREATE TABLE storehouse_shop_prod(
shop_product_id BIGINT(64),
storehouse_id INT(32),
stock INT(32),
remarks VARCHAR(50),
PRIMARY KEY (storehouse_id,shop_product_id)
) ENGINE=InnoDB CHARSET=utf8
2015-11-10 15:32:33,647 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:212) DEBUG - SELECT * FROM t_demo_test_pks  WHERE pka=? AND pkb=? 
    | 1 | 2 |
    |---|---|
    | 1 | 2 |
  For example:> "SELECT * FROM t_demo_test_pks  WHERE pka=1 AND pkb=2 "

PS: 贴代码请使用菜单上的代码标签

@wendal OK,thankyou,终于知道原因了。教授果然牛啊

@fwm520 啥原因

来自炫酷的 NutzCN

@fwm520 是@one里面的field 和key 搞反了么

@wendal @one里面应该是field ="storehouseId" ,才对吧

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