In the JPA 2.1 specification (JSR 338), I canβt find any hint that fetch connections only work with entity relationships (but not embeddable ones). JSR 338, section 4.4.5.3 even states:
A FETCH JOIN allows you to retrieve an association or collection of elements as a side effect of query execution.
As another hint of the following minimal example (essentially resembling yours) performed with Hibernate 4.3.11, since the JPA provider leads to one request:
Embeddable address:
@Embeddable public class Address { private String city; }
The essence of the employee:
@Entity public class Employee { @Id private Long id; @ElementCollection(fetch = FetchType.LAZY) @CollectionTable(name = "address", joinColumns = @JoinColumn(name="employee_id")) private Set<Address> addresses; }
JPQL query:
em.createQuery("select e from Employee e join fetch e.addresses").getResultList();
The resulting SQL query:
select employee0_.id as id1_1_, addresses1_.employee_id as employee1_1_0__, addresses1_.city as city2_5_0__ from Employee employee0_ inner join address addresses1_ on employee0_.id=addresses1_.employee_id
So the aforementioned JPQL query seems to solve your problem.
source share