Allow EntityGraphs to control loading of basic entity state (not just associations)

Description

The central discussion is this passage from the JPA spec (2.1, section 3.7.4):

The persistence provider is permitted to fetch additional entity state beyond that specified by a fetch graph or load graph. It is required, however, that the persistence provider fetch all state specified by the fetch or load graph.

Essentially a JPA provider is free to load as much state as they want in conjunction with an EntityGraph, so long as they load what the user asked for. In other words if an EntityGraph indicates we should load a Person's name, a provider is free to also load the Person's other attributes. All the spec says is that the Person's name must be loaded.

And in Hibernate's impl we load all non-Collection (plural attribute) state for each node in the graph.

In conjunction with bytecode enhancement, @LazyGroup and the SQM work we should be able to more selectively apply what to load in each case.


Original Description


The JPA 2.1 specification gives the following example on how to implement the fetching of attributes that are not specified in the @NamedEntityGraph:

In the above example, only the number attribute would be eagerly fetched."
[Section 3.7.4]

In my code I have a CustomerEntity with the following @NamedEntityGraph:

The generated SQL is:

Despite the @NamedEntityGraph the fields numberOfPurchases of CustomerEntity and timestamp of OrderEntity are loaded, which should not be the case according the example in the specification. The field addresses of the CustomerEntity is not loaded. Hence it seems that the @NamedEntityGraph only affects fields that are Collections, but fields that are not a Collection are always loaded.

Environment

Hibernate version 4.3.5.Final in JBoss Wildfly 8.1.0CR2, H2 database

Status

Assignee

Unassigned

Reporter

Martin Mois

Fix versions

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Priority

Major
Configure