2017  Kodetalk | Feedback | Privacy Policy | Terms | About

hibernate criteria api join table problem

i cannot use sorting on join tables. Let me explain;

i have three tables. users, groups and user_groups. my JPA entities are User, UserGroup, UserGroupPK, Groups.

in fact the output that i want is: "SELECT * FROM user_groups ug JOIN users u ON u.ID = ug.UserID ORDER BY u.name;"

so i try to use hibernate criteria API.

CriteriaImpl criteria = (CriteriaImpl) session.createCriteria(UserGroup.class);
List userGroups = criteria.list();

The error is could not resolve property: pk.user.name of: models.UserGroup

how can i use criteria API on join tables?

it is quite easy just use createCriteria on the associations:
Criteria c=session.createCriteria(Users.class)

Hope this will help  you.

Answer is