I have two tables Employee and Department following are the entity classes for both of them
Department.java
@Entity
@Table(name = \"DEPARTMENT\")
public clas
I'd say it depends...
Let assume you have N employees in a department, that contains D bytes of information and an average employee consist of E bytes. (Bytes are sum of the attribute length with some overhead).
Using the join strategy you perform 1 query and transfers N * (D + E) data.
Using the subquery strategy you perform 1 + N queries, but transfers only D + N*E data.
Typically the N+1 query is the NO GO if the N is large, so the JOIN is preferred.
But actually you must check your mileage between number of queries and data transfer.
Note that I'm not considering other aspects as Hibernate caching.
Additional subtle aspect could be valid if the employee table is large and partitioned - partition pruning on the index access comes to the consideration as well.