aspose file tools*
The moose likes Object Relational Mapping and the fly likes Difference between Fetch Join and inner join Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Difference between Fetch Join and inner join" Watch "Difference between Fetch Join and inner join" New topic
Author

Difference between Fetch Join and inner join

Anuj Singhal
Greenhorn

Joined: Oct 17, 2003
Posts: 23

Refer below extract from specification , section 4.4.5.
-----------------------------------------------------------------------------------------------------------------------
SELECT d
FROM Department d LEFT JOIN FETCH d.employees
WHERE d.deptno = 1


A fetch join has the same join semantics as the corresponding inner or outer join, except that the related
objects specified on the right-hand side of the join operation are not returned in the query result or otherwise
referenced in the query. Hence, for example, if department 1 has five employees, the above query
returns five references to the department 1 entity.

-----------------------------------------------------------------------------------------------------------------------

I am not clear on above paragraph. The above query will return 5 references when inner join is used or when fetch join is used?

What will be the difference in behavior between below two queries?
a)
SELECT d
FROM Department d LEFT JOIN d.employees e
WHERE d.deptno = 1

b)
SELECT d
FROM Department d LEFT JOIN FETCH d.employees
WHERE d.deptno = 1


Thanks,
Anuj
Anuj Singhal
Greenhorn

Joined: Oct 17, 2003
Posts: 23
Will a) return just one reference of department object, whereas b) will return 5 references of Dept object?
 
Consider Paul's rocket mass heater.
 
subject: Difference between Fetch Join and inner join