日期:2014-05-17  浏览次数:20708 次

删除操作如何改用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();}
    }