当前位置: 代码迷 >> Java Web开发 >> 删除操作怎么改用hibernate的hql
  详细解决方案

删除操作怎么改用hibernate的hql

热度:5071   发布时间:2013-02-25 21:09:20.0
删除操作如何改用hibernate的hql?
Java code
            String delStr = "delete from PLM_EDITLOCK where OBJECTID="+caseId+" and USERID='"+userId+"'";            try{                Session session = HibernateUtil.currentSession();                session.connection().createStatement().execute(delStr);            }catch(Exception se){                //throw se;                System.err.println("delete error!");            }


我现在是这样做的,如果改用hibernate的hql要怎么写?

------解决方案--------------------------------------------------------
Java code
public static void UpdateSQL(String SqlStr){        try{            session = HibernateUtil.currentSession();            Transaction tx= session.beginTransaction();            Query query = session.createQuery(SqlStr);            query.setCacheable(false);            query.executeUpdate();            tx.commit();        }        catch (HibernateException e) {            e.printStackTrace();        }        finally{HibernateUtil.closeSession();}    }
  相关解决方案