Introduce the emp table :
CREATE TABLE emp
( id NUMBER
, name VARCHAR
, dept_code VARCHAR
)
and table dept :
CREATE TABLE dept
( code VARCHAR
, name VARCHAR
)
emp.dept_codelinks dept.codelike ForeignKey.
These tables are mapped to JPA objects, and ForeignKey is modeled as an association:
@ManyToOne
@JoinColumn(name = "dept_code")
private Department department;
Given the following data:
emp dept
---------------- ------------------
1 John SALS SALS Sales
2 Louis SALS SUPT Support
3 Jack SUPT
4 Lucy SUPT
I would like to write a JPA request that returns all Emloyees employees to the support department. Suppose I know PrimaryKey support department ( SUPT)
I assume it will be:
SELECT emp
FROM Employee emp JOIN emp.department dept
WHERE dept.code = 'SUPT'
Question:
Since SUPTthe department key is available in the emp table , is there a way to rewrite the JPA request by avoiding the JOIN for the department unit?
? JPA (, Hibernate) , dept?