hibernate 更新操作

单表更新

(1)Query q = session.createQuery( "update NoticeListSend set notice_Del='1' where list_Send_Id in ("+ ids + ")" );
       q.executeUpdate();

(2)Query q = session.createQuery( "update NoticeListSend set noticeDel='1' where listSendId in (:ids)" );
       q.setParameterList( "ids", ids );
       q.executeUpdate();

多表

(1) Query q = session.createQuery( "update com.coob.notice.vo.TabPNoticeListSend set notice_Del='1'" +
      " where list_Send_Id in (select nl.noticeListId from com.coob.notice.vo.TabPNoticeList nl where list_Send_Id=notice_List_Id and user_Id=:userId)" );
      q.setLong( "userId", userId.longValue() );
      q.executeUpdate();

(2)Query q = session.createQuery( "update com.coob.notice.vo.TabPNoticeListSend set notice_Del='1'" +
        " where list_Send_Id in (select nl.noticeListId from com.coob.notice.vo.TabPNoticeList nl where list_Send_Id=nl.noticeListId and user_Id=:userId)" );
     q.setLong( "userId", userId.longValue() );
      q.executeUpdate();

其中子查询nl.noticeListId 一定要带nl前缀。

 

你可能感兴趣的:(Hibernate)