黑马程序员技术交流社区

标题: 请教下Java中update的写法问题 [打印本页]

作者: saiqqww234    时间: 2016-5-6 23:37
标题: 请教下Java中update的写法问题
Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
session.beginTransaction();
Integer id=UserContext.getUserId();
Date date=new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString=format.format(date);
String sql="update IosaSectionDO t set t.chiefAuditor='"+userId+"' , t.last_modifier="+id+" ,t.lastUpdate=to_date('"+dateString+"','YYYY/MM/DD HH24:MI:SS') where t.id="+sectionId;
Query query = session.createQuery(sql);
int i=query.executeUpdate();
session.getTransaction().commit();


这种样式转换成内部update的实现,应该怎么写,我写了一个一直报错:
String hql="from IosaSectionDO t where t.sectionId=?";
List<IosaSectionDO>lists=this.getHibernateTemplate().find(hql,Integer.valueOf(sectionId));
//Map<String,Object>map=new HashMap<String,Object>();
if(lists.size()>0){
IosaSectionDO iac=new IosaSectionDO();       
iac.setChiefAuditor(lists.get(0).getChiefAuditor());
this.update(iac);       
}


请各位大神指点下





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2