title: Spring Data 2.0.x AuditorAware getCurrentUser method throws AbstractMethodError
body: <p>I am trying to implement <code>AuditorAware</code> into my web application. Below is the list of my library version:<br></p>
  
  <ul>
  <li>jsf 2.2.13</li>
  <li>hibername 5.1.3.Final</li>
  <li>spring 5.0.3.RELEASE</li>
  <li>spring-data 2.0.3.RELEASE</li>
  <li>spring-security 5.0.1.RELEASE</li>
  </ul>
  
  <p>This is my persistence config file:</p>
  
  <pre><code>@Configuration
  @EnableJpaAuditing(auditorAwareRef = "auditorAware")
  @EnableAspectJAutoProxy(proxyTargetClass = true)
  @EnableTransactionManagement
  public class PersistenceContext
  {
       @Bean
       public AuditorAware&lt;AccountModel&gt; auditorAware()
       {
           return new AuditorAwareImpl();
       }
  }
  </code></pre>
  
  <p>And this is my AuditorAwareImpl class:</p>
  
  <pre><code>public class AuditorAwareImpl implements AuditorAware&lt;AccountModel&gt;
  {
      @Override
      public Optional&lt;AccountModel&gt; getCurrentAuditor()
      {
          return Optional.ofNullable((AccountModel) SecurityContextHolder.getContext().getAuthentication().getPrincipal());
      }
  }
  </code></pre>
  
  <p>AccountModel:</p>
  
  <pre><code>@Entity(name = "Account")
  @Table(name = "account")
  public class AccountModel extends BaseModel implements UserDetails
  {
      private static final long serialVersionUID = -4792614546550769652L;
  
      @Column(name = "username", length = 20, nullable = false)
      private String username;
  
      @Column(name = "password", length = 100, nullable = false)
      private String password;
  
      @Column(name = "email", length = 100, nullable = false)
      private String email;
  
      @Column(name = "accPackage", length = 2, nullable = false)
      private String accPackage;
  
      @OneToMany(mappedBy = "account", cascade = CascadeType.ALL)
      private Set&lt;RoleModel&gt; role = new HashSet&lt;RoleModel&gt;();
  
      @Transient
      private transient Set&lt;GrantedAuthority&gt; authorities;
  }
  </code></pre>
  
  <p>BaseModel:</p>
  
  <pre><code>@MappedSuperclass
  @EntityListeners(AuditingEntityListener.class)
  public abstract class BaseModel implements Serializable
  {
      private static final long serialVersionUID = -8027746305948051121L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id", nullable = false, updatable = false)
      private Integer id;
  
      @CreatedBy
      @ManyToOne
      @JoinColumn(name = "createdBy", nullable = true, updatable = false)
      private AccountModel createdBy;
  
      @CreatedDate
      @Temporal(TemporalType.TIMESTAMP)
      @Column(name = "dateCreated", nullable = false, updatable = false)
      private Date dateCreated;
  
      @LastModifiedBy
      @ManyToOne
      @JoinColumn(name = "modifiedBy", insertable = false)
      private AccountModel modifiedBy;
  
      @LastModifiedDate
      @Temporal(TemporalType.TIMESTAMP)
      @Column(name = "dateModified", insertable = false)
      private Date dateModified;
  
      @Version
      @Column(name = "verCtrl", nullable = false)
      private Integer version;
  }
  </code></pre>
  
  <p>When I try to persist an object, AbstractMethodError will be thrown:</p>
  
  <pre><code>Caused by: java.lang.AbstractMethodError: com.project.core.AuditorAwareImpl.getCurrentAuditor()Ljava/lang/Object;
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
      at com.sun.proxy.$Proxy71.getCurrentAuditor(Unknown Source)
      at org.springframework.data.auditing.AuditingHandler.touchAuditor(AuditingHandler.java:166)
      at org.springframework.data.auditing.AuditingHandler.touch(AuditingHandler.java:145)
      at org.springframework.data.auditing.AuditingHandler.markCreated(AuditingHandler.java:125)
      at org.springframework.data.jpa.domain.support.AuditingEntityListener.touchForCreate(AuditingEntityListener.java:83)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.hibernate.jpa.event.internal.jpa.ListenerCallback.performCallback(ListenerCallback.java:35)
      ... 124 more
  </code></pre>
  
  <p><br><strong>UPDATE</strong><br><br>
  After I have changed my Spring Data from 2.x to 1.x, it works, no more exception. I think the problem is with the return data type of the <code>getCurrentUser()</code> method. In 1.x, return datatype is simply your custom <code>UserDetails</code> object, but in 2.x, the return datatype is <code>Optional&lt;CustomModel&gt;</code>. Could it possible be the cause of error?</p>