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);
請先 登入 以發表留言。