views:

726

answers:

1

I'm having real difficulty getting the eclipselink.join-fetch hint to work in glassfish.

I have a Client object that contains a collection of Task objects and the Task object has a collection of WorkPeriod objects.

My code looks like this:

Query query = entityManager.createQuery("select client from Client client left join fetch client.tasks");   
//Set hint to allow nested fetch joins
query.setHint("eclipselink.join-fetch","client.tasks.workPeriods");
List<Client> clients = query.getResultList();

But no matter what I do when I set the TOPLINK debug level to fine it always shows that the SQL which is actually run is:

SELECT t0.ID, t0.NAME, t1.ID, t1.DESCRIPTION FROM CLIENT t0 LEFT OUTER JOIN (CLIENT_TASK t2 JOIN TASK t1 ON (t1.ID = t2.tasks_ID)) ON (t2.Client_ID = t0.ID)

Clearly not doing the third tier of the join fetch.

Has anyone else had problems with this... or is it just me :-(

Any help or hints (no pun intended) would be much appreciated.

A: 

OK, after 8 hours of frustration I've got to the bottom of it.

Glassfish V2 doesn't use EclipseLink as it's persistence provider, it uses Toplink Essentitals. Unfortunately Toplink essentials doesn't provide a join-fetch hint (I was very confused by the following link which made me think it did: https://glassfish.dev.java.net/issues/show_bug.cgi?id=1200 although this is obviously a feature request NOT a feature).

So it would appear that what I'm attempting to do is not possible and if I want to do multi-level eager fetch in glassfish I'm going to have to get the EntityManagers delegate and use the toplink essentials Expressions directly.

montyontherun

related questions