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要怎么写?

解决方案 »

  1.   

    忘了说了,where里的几个字段都不是主键
      

  2.   


    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();}
    }DataDAO.UpdateSQL(delStr);delStr 表名 和 字段名 要以 hbm.xml 为准
      

  3.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【ms_ms】截止到2008-07-08 12:09:09的历史汇总数据(不包括此帖):
    发帖的总数量:59                       发帖的总分数:1740                     每贴平均分数:29                       
    回帖的总数量:87                       得分贴总数量:21                       回帖的得分率:24%                      
    结贴的总数量:58                       结贴的总分数:1720                     
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:1                        未结的总分数:20                       
    结贴的百分比:98.31 %               结分的百分比:98.85 %                  
    无满意结贴率:0.00  %               无满意结分率:0.00  %                  
    值得尊敬
      

  4.   


    DataDAO.UpdateSQL(delStr); delStr 表名 和 字段名 要 hbm.xml 为准
      

  5.   

    如果是用了spring直接就是调用getHibernateTemplate().delete(entity);
    entity就是你的hbm.xml对应的映射类的对象。
      

  6.   

    HQL应该对应的是映射类的属性吧?
      

  7.   

    session = HibernateUtil.currentSession();
    用currentSession在commit的时候session会自动关闭
    不需要手动调用session.close()来关闭
      

  8.   

    String hql= "delete from 对象(实体) as t where t.OBJECTID(实体属性)=1? and t.USERID(实体属性)=2?";
    try{
       session = HibernateUtil.currentSession(); 
       Transaction tx= session.beginTransaction(); 
       Query q = session.createQuery(hql); 
       q.set(OBJECTID)类型(0, 1?);
       q.set(USERID)类型(0, 2?);
       q.executeUpdate(); 
       tx.commit(); 
    }catch (HibernateException e) { 
          … 
      

  9.   

    我想用delete方法删除,类似  session.Delete("from BZ0201  where Id in ?",Convert.ToInt64(2), NHibernateUtil.Int64);却报错,为什么。。