1 Reply Latest reply on Sep 29, 2006 11:41 AM by Pete Muir

    how to write a code

    Nako Ruru Newbie

      I have 3 classes. User, RoleRef, Role

      public class User {
      
       public void setId(int id) {
       ...
       }
      
       public int getId() {
       return ...;
       }
      
      }
      


      public class Role {
      
       public void setId(int id) {
       ...
       }
      
       public int getId() {
       return ...;
       }
      
      }
      


      public class RoleRef {
      
       private User user;
       private Role role;
      
       public User getUser() {
       return user;
       }
      
       public Role getRole() {
       return role;
       }
      
       public void setUser(User user) {
       this.user = user;
       }
      
       public void setRole(Role role) {
       this.role = role;
       }
      
       public boolean equals(Object o) {
       if(o == this) {
       return true;
       } else if(o == null) {
       return false;
       } else if(o instanceof RoleRef) {
       RoleRef referrence = (RoleRef) o;
       return user.equals(referrence.user) && role.equals(referrence.role);
       } else {
       return false;
       }
       }
      
      }
      


      The mapped tables are respective role, roleref, user.

      Now assume that I have an instance of User, how can I write criteria code which is the same as sql expression as below.

      "select role.* from user, roleref, role where user.id = roleref.uid && roleref.rid = role.id".