title: Strange behaviour when integrate Spring JPA Data and Spring Cache
body: <p>When I integrate Spring JPA Data and Spring Cache, there is a strange behaviour I can't explain.</p>
  
  <p>I am using Spring Boot to setup my demo project. The code is below.</p>
  
  <p>My config bean:</p>
  
  <pre><code>@Configuration
  public class AppConfig {
  
      @Bean
      public CacheManager cacheManager() {
          return new ConcurrentMapCacheManager("Person");
      }
  }
  </code></pre>
  
  <p>My entity bean.</p>
  
  <pre><code>@Entity
  public class Person implements Serializable {
  
      private static final long serialVersionUID = 2263555241909370718L;
  
      @Id
      @GeneratedValue
      private Long id;
  
      private String name;
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
  }
  </code></pre>
  
  <p>My JPA interface. I overwrite some methods from JpaRepository and add @cachable annotation.</p>
  
  <pre><code>public interface PersonRepository extends JpaRepository&lt;Person, Long&gt; {
  
      @Override
      @CacheEvict(value = "Person", allEntries = true)
      public void delete(Long id);
  
      @Cacheable("Person")
      public Person findByName(String name);
  
      @Override
      @Query("select p from Person p where p.id = :id + 1L")
      @Cacheable("Person")
      public Person findOne(@Param("id") Long id);
  }
  </code></pre>
  
  <p>My unit test class</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @SpringApplicationConfiguration(classes = SpringDataDemoApplication.class)
  public class SpringDataDemoApplicationTests {
  
      @Autowired
      private PersonRepository personRepository;
  
      @Autowired
      private CacheManager cacheManager;
  
      @Before
      public void setup() {
          Person p1 = new Person();
          p1.setName("Chris");
          personRepository.save(p1);
      }
  
      @Test
      public void test2() {
  
          JpaRepository&lt;Person, Long&gt; jpaRepository = personRepository;
  
          Person p = personRepository.findOne(0L);
          Assert.assertNotNull(p);
  
          p = personRepository.findOne(0L);
          Assert.assertNotNull(p);
  
          System.err.println("---------------------------------------");
  
          p = jpaRepository.findOne(0L);
          Assert.assertNotNull(p);
  
          p = jpaRepository.findOne(0L);
          Assert.assertNotNull(p);
      }
  
  }
  </code></pre>
  
  <p>The output is very strange.</p>
  
  <pre><code>Hibernate: insert into person (id, name) values (default, ?)
  Hibernate: select person0_.id as id1_0_, person0_.name as name2_0_ from person person0_ where person0_.id=?+1
  ---------------------------------------
  Hibernate: select person0_.id as id1_0_, person0_.name as name2_0_ from person person0_ where person0_.id=?+1
  Hibernate: select person0_.id as id1_0_, person0_.name as name2_0_ from person person0_ where person0_.id=?+1
  </code></pre>
  
  <p>It should only print out one sql statement for my expect. The <code>jpaRepository.findOne(0L)</code>  doesn't use the cache object.</p>
  
  <p>The cache annotation is not working after I assign the PersonRepository interface to its parent interface, JpaRepository. </p>
  
  <p>These 2 variables are exactly point to the same reference, even it a proxy object. Why call the same reference's method causing 2 difference result?</p>
  
  <p>I also notice that the @Query annotation is working well. Both the JpaRepository and PersonRepository references use the customized SQL. </p>
  
  <p>I guess there maybe some differences between how Spring Cache and Spring JPA Data generate the proxy advisor. Is that possible a bug here?</p>