title: entitygraph not working - returning all the entity
body: <p>I'm trying the EntityGraph in a simple scenario of springdata jpa:</p>
  
  <p>The idea is just to get an entity with its id field and omit another field called name.</p>
  
  <p>This is the entity to be retrieved:</p>
  
  <pre><code>Entity
  @NamedEntityGraph(name = "Region.id",
          attributeNodes = @NamedAttributeNode("id"))
  public class Region {
      @Id
      public String id;
  
      public String name;
  
  
  
      public String getId() {
          return id;
      }
  
      public void setId(String id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  }
  </code></pre>
  
  <p>The repository:</p>
  
  <pre><code>public interface RegionRepository extends JpaRepository&lt;Region, String&gt;{
  
      @EntityGraph(value = "Region.id")
      Region findByRegionId(String name);
  
  }
  </code></pre>
  
  <p>And a Service:</p>
  
  <pre><code>@Service
  public class RegionService {
  
      @Autowired
      private RegionRepository regionRepository;
  
  
      public Region getRegion(String regionId) {
          Region region = regionRepository.findByRegionId(regionId);
          return region;
      }
  }
  </code></pre>
  
  <p>As mentioned the whole Region is retrieved.</p>
  
  <p>I tried another way by using a bit more code.</p>
  
  <p>Added an interface:</p>
  
  <pre><code>public interface RegionRepositoryCustom {
      Region findByRegionId(String name);
  }
  </code></pre>
  
  <p>And used it to add an impl class:</p>
  
  <pre><code>
  public class RegionRepositoryImpl  implements RegionRepositoryCustom{
      @PersistenceContext
      private EntityManager em;
  
      @Override
      @Transactional
      public Region findByRegionId(String id) {
  
          EntityGraph&lt;Region&gt; entityGraph = (EntityGraph&lt;Region&gt;) em.getEntityGraph("Region.id");
  
          Region region = em.createQuery("select r from Region r where r.id = :id", Region.class)
                  .setParameter("id", id)
                  .setHint("javax.persistence.fetchgraph", entityGraph)
                  .getSingleResult();
  
          return region;
      }
  
  }
  </code></pre>
  
  <p>And tried this variant:</p>
  
  <pre><code>
  public class RegionRepositoryImpl  implements RegionRepositoryCustom{
      @PersistenceContext
      private EntityManager em;
  
      @Override
      @Transactional
      public Region findByRegionId(String id) {
  
          //EntityGraph&lt;Region&gt; entityGraph = em.createEntityGraph(Region.class);
          //entityGraph.addAttributeNodes("id");
  
          EntityGraph&lt;Region&gt; entityGraph = (EntityGraph&lt;Region&gt;) em.getEntityGraph("Region.id");
  
          Map&lt;String, Object&gt; properties = new HashMap&lt;&gt;();
          properties.put("javax.persistence.fetchgraph", entityGraph);
  
          Region region = em.find(Region.class, id, properties);
  
  
          return region;
      }
  
  }
  
  </code></pre>
  
  <p>Also using H2 with application.properties setting:</p>
  
  <pre><code>spring.jpa.show-sql=true
  
  spring.jpa.properties.hibernate.format_sql=true
  
  
  
  spring.datasource.url=jdbc:h2:mem:AZ;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE
  spring.datasource.username=sa
  spring.datasource.password=
  spring.datasource.driver-class-name=org.h2.Driver
  
  spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
  
  spring.jpa.hibernate.ddl-auto=create-drop
  
  spring.jackson.serialization.FAIL_ON_EMPTY_BEANS=false
  </code></pre>
  
  <p>This is the SQL template used seen in the ide's console:</p>
  
  <pre><code>Hibernate: 
      select
          region0_.id as id1_0_,
          region0_.name as name2_0_ 
      from
          region region0_ 
      where
          region0_.id=?
  
  </code></pre>
  
  <p>All did not work...</p>
  
  <p>What am I missing?</p>