title: How to force @Cacheable work after method execution in spring 3?
body: <p>I have method that saves entity into database.It is:</p>
  
  <pre><code>@Cacheable(value = EMPLOYEE_CACHE,key="#employee.id")
      public Employee createEmployee(Employee employee) {
          try {
              entityManager.persist(employee);
          } catch (Exception e) {
              return null;
          }
          return employee;
      }
  </code></pre>
  
  <p>I want the result <code>Employee</code> to be cached by key = <code>id</code> of <code>Employee</code>. Employee's <code>id</code> is assigned after <code>entityManager,persist</code> method runs.
  I know that <code>@Cacheable</code> works because of AOP. By default, it stores <code>employee</code> into cache before method <code>createEmployee</code> runs. </p>
  
  <p>How to force <code>org.springframework.cache.annotation.@Cacheable</code> to store into cache after method execution?</p>
  
  <p>The <strong>stacktrace</strong> :</p>
  
  <pre><code>java.lang.IllegalArgumentException: Null key returned for cache operation (maybe you are using named params on classes without debug info?) CachePutOperation[public com.livelessons.spring.springcore.entities.Employee com.livelessons.spring.springcore.service.EmployeeServiceImpl.createEmployee(com.livelessons.spring.springcore.entities.Employee)] caches=[employees] | key='#employee.id' | condition='' | unless=''
      at org.springframework.cache.interceptor.CacheAspectSupport.inspectCacheUpdates(CacheAspectSupport.java:371)
      at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:202)
      at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:66)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
      at com.sun.proxy.$Proxy30.createEmployee(Unknown Source)
      at com.livelessons.spring.springcore.EmployeeServiceTest.saveEmployee(EmployeeServiceTest.java:59)
      at com.livelessons.spring.springcore.EmployeeServiceTest.testSpringCacheable(EmployeeServiceTest.java:51)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
      at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
      at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
      at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
  </code></pre>