title: Spring AOP and Spring JPA, Aspect to be executed
body: <p>I have been writing an aspect that manipulates some of my JPA entities getters. It is supposed to re-format the returned text based on the clients locale. Because not all of my getters should be reformatted I introduced an annotation <code>@ReFormat</code>. </p>
  
  <p>The problem is my aspect is never intercepted when I advise it to an JPA entity but it works fine on non JPA entities (it works when I create my own entity object via a copy constructor).</p>
  
  <p>My annotation:</p>
  
  <pre><code>@Retention(RetentionPolicy.RUNTIME)
  @Target({ElementType.METHOD, ElementType.TYPE})
  public @interface ReFormat {
  
  }
  </code></pre>
  
  <p>My aspect:</p>
  
  <pre><code>@Aspect
  public class ReFormatAspect {
      @AfterReturning(pointcut = "@annotation(com.path.ReFormat)", returning = "response")
      public Object formatter(JoinPoint joinPoint, Object response) {
         return response;
      }
  }
  </code></pre>
  
  <p>Now this aspect is intercepted successfully within my MVC controllers (or at any other place except spring data) but not for my entities.</p>
  
  <pre><code>@Entity
  @Table(name = "place", schema = "db")
  public class TestEntity {
  
     @Id
     @Column(name = "id")
     protected long id;
  
     @Column(name = "about", columnDefinition = "TEXT DEFAULT NULL")
     protected String about;
  
     @ReFormat
     public String getAbout() {
         return this.about;
     }
  </code></pre>
  
  <p>}</p>
  
  <p>I expected a point cut once the <code>getAbout</code> method is called, but it does not work.</p>
  
  <p>Given the facts above I suppose that JPA (Hibernate) is overriding any interceptor may be by CGLib or javassist.</p>
  
  <p>Note: I have this inside my context</p>
  
  <pre><code>&lt;context:annotation-config /&gt;
  &lt;context:spring-configured /&gt;
  &lt;aop:aspectj-autoproxy proxy-target-class="true" /&gt;
  </code></pre>
  
  <p>So what is the exact issue, and how do I intercept any method inside an entity?</p>
  
  <p><em>I understand this should be the view layer work, but still I need to know why :D</em></p>