0

我的数据库中有三个表,如下所示:

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 实现这一点。

4

0 回答 0