Uploaded image for project: 'Hibernate ORM'
  1. HHH-13152

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

    Details

      Description

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

      This code apply entity graph to loaded entity correctly:

      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

      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();
      

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Feedback Requested: