EntityGraph API: map (key/value) subgraph support broken

Description

When programatically creating EntityGraph subgraphs we need to add subgraphs for keys and values independently using addKeySubgraph(...) and addSubgraph(...) methods. However, each of these method will replace the attribute node from the previous step with a new one. Thus, if we first "add" a key subgraph, adding the value subgraph later will effectively remove the key subgraph and vice versa - if we add the value subgraph first, then the key, the value one will be removed. In other words, the last one wins and the previous state is lost.

For example, given MockEntity.java:

... the following two methods illustrate the the two cases (only the order of adding subgraphs is different):

and:

There is even a debug-level logged note in the org.hibernate.jpa.graph.internal.AbstractGraphNode addAttributeNode() method that seems related to this case (does not expect it) - specifically "Encountered request to add entity graph node [%s] using a name [%s] under which another node is already registered [%s]":

Environment

Any

Assignee

A Susnjar

Reporter

Learner Evermore

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure