• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Difference between Fetch Join and inner join

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will a) return just one reference of department object, whereas b) will return 5 references of Dept object?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!