I have 3 classes. User, RoleRef, Role
Code:
public class User {
public void setId(int id) {
...
}
public int getId() {
return ...;
}
}
Code:
public class Role {
public void setId(int id) {
...
}
public int getId() {
return ...;
}
}
Code:
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".