We're updating the issue view to help you get more done. 

Error loading entity with Entity Graph when entity already stored in session cache

Description

Load entity graph is ignored when entity to load is aready in session cache.

This code apply entity graph to loaded entity correctly:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 entityManager = entityManagerFactory.createEntityManager(); entityManager.getTransaction().begin(); //Relaod same product but now providing an EntityGraph with contents EntityGraph<ProductDL> eg=entityManager.createEntityGraph(ProductDL.class); eg.addSubgraph("contents"); Map<String,Object> props=new HashMap<String,Object>(); props.put( "javax.persistence.loadgraph", eg); productDL=entityManager.find(ProductDL.class,productDL.getId(),props); entityManager.getTransaction().commit(); entityManager.close(); productDL.getContents();

This code doesnt works. Before read entity with Entity Graph, we load entity so its stored in session cache. When entity is readed with entity graph it is returned from session cache wihouth applying Entity Graph

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 entityManager = entityManagerFactory.createEntityManager(); entityManager.getTransaction().begin(); //Load product and store it in session cache //Removing this line code works well due to "Product 1" dont be cached in session cache! entityManager.find(ProductDL.class,productDL.getId()); //Relaod same product but now providing an EntityGraph with contents EntityGraph<ProductDL> eg=entityManager.createEntityGraph(ProductDL.class); eg.addSubgraph("contents"); Map<String,Object> props=new HashMap<String,Object>(); props.put( "javax.persistence.loadgraph", eg); productDL=entityManager.find(ProductDL.class,productDL.getId(),props); entityManager.getTransaction().commit(); entityManager.close(); //Product without resolve its contents productDL.getContents();

Environment

None

Status

Assignee

Steve Ebersole

Reporter

Domingo Delgado Guillén

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

backportDecision

None

Feedback Requested

2018/12/11

Worked in

5.3.7

Components

Affects versions

5.4.0.CR1
5.3.7

Priority

Major