SessionFactory.CONFIG_FILE_LOCATION="/hibernate.cfg.xml";Object session_id=SessionFactory.createSession();Session hsession=SessionFactory.getSession();Query query=null;MyObject obj=(MyObject)hsession.get(MyObject.class,new Integer(1));obj.setAttribute("new attribute");Transaction tx = hsession.beginTransaction();try {	hsession.update(obj);	tx.commit();	//更新快取	hsession.refresh(obj);}catch(HibernateException e) {	if(tx != null) {		try {	       		tx.rollback();		}		catch(HibernateException ex) {			ex.printStackTrace();		}	}}SessionFactory.closeSession(session_id);
創作者介紹
創作者 gan068 的頭像
gan068

gan068

gan068 發表在 痞客邦 留言(0) 人氣( 33 )