I have three tables and I want to map all data in them into List of entities, each containing List of another entities.
user user_role
┌─────┐1 ┌──────────┐ role
│ id ├──┤ user_id │* ┌─────┐
├─────┤ *│ role_id ├──┤ id │
│name │ ├──────────┤ 1├─────┤
└─────┘ │ given_by │ │name │
└──────────┘ └─────┘
I want to map it's data to List of UserWithRolesAndGivers
. Entities are below.
public class UserWithRolesAndGivers {
private String userName;
private List<RoleAndGiver> roleAndGivers;
}
public class RoleAndGiver {
private String roleName;
private String givenBy;
}
How can I achieve this using hibernate?