8 Replies Latest reply on Feb 22, 2007 3:57 PM by Micho Edershvili

    relationship does not prevent from deleting referenced entit

    Micho Edershvili Newbie

      I thougtht, that the definition of a unidirectional relationship without cascading delet would prevent the Entities from deletion

      Example:
      unidirectional many-to-many relationship between user and usergroup.
      users know their usergroups,
      usergroups do not know their users

      It shold not be possible to delete a usergroup which is in an relationship to a (or many) user

      I coded like this, what have I done wrong?

      Thanks Micho

      @Entity
      public class Usergroup implements Serializable
      { private long mSid;
       private String mName;
      
       public BenutzerGruppe()
       { super(); }
      
       @Id @GeneratedValue(strategy=GenerationType.AUTO)
       public long getSid()
       { return mSid; }
      
       public void setSid(long sid)
       { mSid = sid; }
      
       public String getName()
       { return mName; }
      
       public void setName(String pName)
       { this.mName = pName; }
      }
      

      @Entity
      public class User implements Serializable
      { private long mSid;
       private String mName;
       private List<Usergroup> mUsergrouplist;
      
       public User()
       { super(); }
      
       public String getName()
       { return mName; }
      
       public void setName(String pName)
       { mName = pName;}
      
       @Id @GeneratedValue(strategy=GenerationType.AUTO)
       public long getSid()
       { return mSid; }
      
       public void setSid(long pSid)
       { mSid = pSid; }
      
       @ManyToMany
       ( targetEntity = Usergroup.class )
       public List<Usergroup> getUsergrouplist()
       { return mUsergrouplist; }
      
       public void setUsergrouplist(List<Usergroup> pUsergrouplist)
       { mBenutzerGruppeListe = pBenutzerGruppeListe; }
      }