1. 程式人生 > >hibernate manytomany 只刪除本表和中間表數值

hibernate manytomany 只刪除本表和中間表數值

public String deleteSpri() {
  try {
   SPrivlege s = this.sPrivlegeManager.getSPriv(sp);

  /**獲取s關聯的所有GROUP物件集合**/
   Set<Group> groups=s.getGroups();

  
   for(Group g:groups){

    /**取消關聯**/
    g.getSprivleges().remove(s);
   }

    /**刪除**/
   this.sPrivlegeManager.delete(s);
   return SUCCESS;

  } catch (Exception e) {
   System.out.println(e.getMessage());
   return

   ERROR;
  }
 }