Affects Version/s: None
Fix Version/s: None
JPA 2.1 spec proposal extends the fetch joins with the addition of 'ON' specification.
Fetch joins are for eager loading and plain joins are for resultset restrictions.
According to specification when within a transaction, entities returned by a JPQL or Crtieria API are managed.
So restricting fetch joins with ON extension alters the relation in a way that the original relations are represented with an inconsistent managed relations. An modification to the relations will create a corrupt the data graph.
A Transaction is active
Persons are queried and in ON clause their addresses are restricted to Address.primary = true
One of the Person(s) has 2 addresses. Yet only the Address that is primary loaded as part of the query.
The Business layer adds a new Address to Person's addresses collection.
When the EntityManager is flushed inadvertently the non-primary address gets removed from the relation.
If you work this around by marking the collection as 'unmanaged', then a further find() operation will return again inconsistent Person object with only one address and Person's addresses collection is refetched with full contents, then you will have an inconsistency in the EntityManager that same person with two collections representing different child entities.
While this is the case with Fetch Joins, there should be no problem with plain Joins as they do not get used to populate the relations but merely restrict the ResultList.