我的数据库中有三个表格如下:
mysql> desc employee;
+--------------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+------------------+------+-----+---------+-------+
| empId | int(10) unsigned | NO | PRI | 0 | |
| empName | varchar(45) | NO | | | |
| jobCode | int(10) unsigned | YES | MUL | NULL | |
| locationCode | int(10) unsigned | YES | MUL | NULL | |
+--------------+------------------+------+-----+---------+-------+
mysql> desc job;
+---------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+------------------+------+-----+---------+-------+
| jobCode | int(10) unsigned | NO | PRI | 0 | |
| jobName | varchar(45) | NO | | | |
+---------+------------------+------+-----+---------+-------+
mysql> desc location;
+--------------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+------------------+------+-----+---------+-------+
| locationCode | int(10) unsigned | NO | PRI | 0 | |
| locationName | varchar(45) | NO | | | |
+--------------+------------------+------+-----+---------+-------+
我的SQL查询是:
SELECT e.empName, j.jobName, l.locationName
FROM employee e, job j, location l
WHERE e.empId = '101' and e.jobCode = j.jobCode and e.locationCode = l.locationCode;
如何使用JPA(Hibernate)CriteriaQuery实现此功能。