NutzCN Logo
问答 关于updateWithVersion必须有@Name/@Id/@PK问题
发布于 2609天前 作者 naxxm 1981 次浏览 复制 上一个帖子 下一个帖子
标签:

测试是,类拥有@Name是可以正常更新数据,仅有@PK时无法跟新数据~
类:

@Table("t_sys_employee")
@PK(value = { "id","bm" })
public class SysEmployee {
	//@Name//字符主键
	@Prev(els = { @EL("uuid()") })
	@Comment("uuid主键唯一")//字段注释
	@ColDefine(type = ColType.VARCHAR,width = 32)//字段类型
	@Column("uuid")
	private String id;
	
	@Comment("版本")
	@Column(version=true)
	private long version;
	
	@Prev(els = { @EL("uuid()") })
	@Comment("员工编号")//字段注释
	@ColDefine(type = ColType.VARCHAR,width = 32)//字段类型

测试代码:(这个查询后应该是直接提交数据库的吧,因为@Name时是直接就更新了数据库的)

sysEmployee = dao.fetch(SysEmployee.class, Cnd.where("name", "=", username).and("password", "=", password));				
		if(sysEmployee != null){
			
			sysEmployee.setBm("9003");
			dao.updateWithVersion(sysEmployee);
			
			sysCompany = dao.fetch(SysCompany.class, Cnd.where("bm", "=", sysEmployee.getGs_bm()));		
		}	

日志:

2017-10-31 21:58:24 select * from(select row_number()over(order by __tc__)__rn__,* from(select top 1 0 __tc__,    * FROM t_sys_employee  WHERE name=? AND password=?)t)tt where __rn__ > 0 order by __rn__ 
    |     1 |      2 |
    |-------|--------|
    | admin | 123456 |
  For example:> "select * from(select row_number()over(order by __tc__)__rn__,* from(select top 1 0 __tc__,    * FROM t_sys_employee  WHERE name='admin' AND password='123456')t)tt where __rn__ > 0 order by __rn__ "
2017-10-31 21:58:24 UPDATE t_sys_employee SET gs_bm=?,md_bm=?,name=?,password=?,role=?,sex=?,mobile=?,wage=?,position=?,entryDate=?,sales=?,state=?  ,version=version+1  WHERE uuid=? AND bm=?  AND version=?
    |    1 |    2 |     3 |      4 |    5 |    6 |    7 |    8 |    9 |   10 |   11 |   12 |                               13 |   14 | 15 |
    |------|------|-------|--------|------|------|------|------|------|------|------|------|----------------------------------|------|---|
    | NULL | NULL | admin | 123456 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | 896a33af3ab84f5096350b41d9ab47e4 | 9003 | 0 |
  For example:> "UPDATE t_sys_employee SET gs_bm='NULL',md_bm='NULL',name='admin',password='123456',role='NULL',sex='NULL',mobile='NULL',wage='NULL',position='NULL',entryDate='NULL',sales='NULL',state='NULL'  ,version=version+1  WHERE uuid='896a33af3ab84f5096350b41d9ab47e4' AND bm='9003'  AND version=0"
2017-10-31 21:58:24 select * from(select row_number()over(order by __tc__)__rn__,* from(select top 1 0 __tc__,    * FROM t_sys_company  WHERE bm IS NULL )t)tt where __rn__ > 0 order by __rn__ 

这里显示的bm = 9003,但是数据库里没有任何变化,还是原来的数据,不知道是什么原因造成的~也没有报错信息

7 回复

那version是多少

0,设置成@PK的字段不能更新,单独跟新其他字段可以更新

感觉不可能,我明天试试

好的~两个符合主键无法更新

试了一下, 没问题的

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