Hibernate4中的事务
Tuser t = userDao.get("from Tuser t where t.name = 'admin' and t.id != 'admin'");
if (t != null) {
t.setName(UUID.randomUUID().toString());
}
上面的执行结果如下:
Hibernate:
select
tuser0_.ID as ID1_,
tuser0_.CREATEDATETIME as CREATEDA2_1_,
tuser0_.MODIFYDATETIME as MODIFYDA3_1_,
tuser0_.NAME as NAME1_,
tuser0_.PWD as PWD1_
from
T_USER tuser0_
where
tuser0_.NAME=?
and tuser0_.ID<>'admin'
Hibernate:
update
T_USER
set
CREATEDATETIME=?,
MODIFYDATETIME=?,
NAME=?,
PWD=?
where
ID=?
Tuser t = userDao.get("from Tuser t where t.name = 'admin' and t.id != 'admin'");
if (t != null) {
t.setName(UUID.randomUUID().toString());
}
Tuser admin = new Tuser();
admin.setId("admin");
admin.setName("admin");
admin.setPwd(Encrypt.e("admin"));
admin.setModifydatetime(new Date());
userDao.saveOrUpdate(admin);
这个的运行结果:
Hibernate:
select
tuser0_.ID as ID1_,
tuser0_.CREATEDATETIME as CREATEDA2_1_,
tuser0_.MODIFYDATETIME as MODIFYDA3_1_,
tuser0_.NAME as NAME1_,
tuser0_.PWD as PWD1_
from
T_USER tuser0_
where
tuser0_.NAME=?
and tuser0_.ID<>'admin'
Hibernate:
select
tuser_.ID,
tuser_.CREATEDATETIME as CREATEDA2_1_,
tuser_.MODIFYDATETIME as MODIFYDA3_1_,
tuser_.NAME as NAME1_,
tuser_.PWD as PWD1_
from
T_USER tuser_
where
tuser_.ID=?
Hibernate:
insert
into
T_USE