0 Replies Latest reply on Apr 15, 2008 3:02 AM by Vemula sriramsudheer

    EntityHome and Deletion operation

    Vemula sriramsudheer Newbie

      Hi All, I was trying to delete an Entity and its Many to Many RelationShip The Following is the code:


      @Name("userHome")
      
      public class UserHome extends EntityHome<User> {
      
           
      
           @Logger Log log;
      
           @In EntityManager entityManager;
      
           @In(required = false) 
      
           UserProfileList userProfileList;
      
           Role selectedRole;
      
           public void setUserUserId(Integer id) {
      
                setId(id);
      
           }
      
      
           public Integer getUserUserId() {
      
                return (Integer) getId();
      
           }
      
      
           @Override
      
           protected User createInstance() {
      
                
      
                User user = new User();
      
                return user;
      
           }
      
      
           public void wire() {
      
           }
      
      
           public boolean isWired() {
      
                return true;
      
           }
      
      
           public User getDefinedInstance() {
      
                return isIdDefined() ? getInstance() : null;
      
           }
      
           
      
           public String validateEntityNotFound() {
      
                try {
      
                     this.getInstance();               
      
                }catch(EntityNotFoundException enfe) {
      
                     return "valid";
      
                }
      
                return this.isManaged()? "invalid" : "valid";
      
           }
      
      
           @Override
      
           public String persist() {
      
                log.info("------Persist User---------");
      
                getInstance().getRoles().add(selectedRole);
      
                return super.persist();
      
           }
      
      
           @Override
      
           public String remove() {
      
                log.info("---------remove User---------");
      
                getInstance().getRoles().remove(selectedRole);
      
                return super.remove();
      
           }
      
      
           @Override
      
           public String update() {
      
                // TODO Auto-generated method stub
      
                log.info("--------update User--------");
      
                return super.update();
      
           }
      
           
      
           public Role getSelectedRole() {
      
                return selectedRole;
      
           }
      
      
           public void setSelectedRole(Role selectedRole) {
      
                this.selectedRole = selectedRole;
      
           }



      When i am adding a User I can see a row in Userroleassn Table but I am Trying to Delete. Its deleting all the Roles and Users associated to that Roles. Could any one please help me in this regard.


      Thanks in advance