I have the following entity structure: Business --> Campaign --> Promotion, where ONE Business can have MANY Campaigns and ONE Campaign can have MANY Promotions. Both one-to-man
Another workaround instead of using Set is to use two queries to get the data :- 1st one to load the campaign and its associated promotions of the business. Then load the Business and its campaigns using fetch
Query query1 = entityManager.createQuery("select c from Business b join b.campaigns c left join fetch c.promotions where b.id=:id");
query1.setParameter("id", b.getId());
query1.getResultList();
Query query2 = entityManager.createQuery("select b from Business b left join fetch b.campaigns where b.id=:id");
query2.setParameter("id", b.getId());
business = (Business) query2.getResultList().get(0);