I have a Dept
table and a Emp
table.
I need to join these two table in such a way that the where
clause looks something like this:
Criteria criteria = session.createCriteria(Dept.class, "department")
.createAlias("empMap", "employee")
.add(Restrictions.eqProperty("department.deptName",
"employee.empTrainingName"));
You may also use a with clause, which would be necessary in case of a left join:
Criteria criteria =
session.createCriteria(Dept.class, "department")
.createAlias("empMap",
"employee",
Criteria.LEFT_JOIN,
Restrictions.eqProperty("department.deptName",
"employee.empTrainingName"));
Side note: your choices of names are awful. Instead of Dept.deptId
, Why not use Department.id
? Instead of Emp.empTrainingName
, why not choose Employee.trainingName
?