title: DynamoDB Spring Boot Data Rest "PersistentEntity must not be null!"
body: <p>I am building a Spring Boot application with DynamoDB. I wanted to add Spring Data REST. The data layer works, but the REST fails on mapping of the entities. It correctly resolves and creates the REST endpoint but I am getting <em>PersistentEntity must not be null!</em> message and an exception when accessing the REST API:</p>
  
  <pre><code>java.lang.IllegalArgumentException: PersistentEntity must not be null!
      at org.springframework.util.Assert.notNull(Assert.java:115)
      at org.springframework.data.rest.webmvc.PersistentEntityResource$Builder.&lt;init&gt;(PersistentEntityResource.java:140)
      at org.springframework.data.rest.webmvc.PersistentEntityResource$Builder.&lt;init&gt;(PersistentEntityResource.java:123)
      at org.springframework.data.rest.webmvc.PersistentEntityResource.build(PersistentEntityResource.java:115)
      at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.wrap(PersistentEntityResourceAssembler.java:74)
      at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.toResource(PersistentEntityResourceAssembler.java:55)
      at org.springframework.data.rest.webmvc.AbstractRepositoryRestController.entitiesToResources(AbstractRepositoryRestController.java:133)
      at org.springframework.data.rest.webmvc.AbstractRepositoryRestController.toResources(AbstractRepositoryRestController.java:80)
      at org.springframework.data.rest.webmvc.RepositoryEntityController.getCollectionResource(RepositoryEntityController.java:212)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
  
  removed irrelevant parts of the exception
  </code></pre>
  
  <p>When I debug the code, I see that the <code>entities</code> in <code>PersistentEntityResourceAssembler</code> is empty. It means my entities were not registered. I guess this is because they are not regular JPA entities and they are only linked through the repositories to the data layer.</p>
  
  <p><strong>How do I let Spring know about my entities in order to make the Data REST framework work with DynamoDB?</strong></p>
  
  <p>Here are relevant parts from my project. The dummy entity representing a table in dynamo:</p>
  
  <pre><code>@DynamoDBTable(tableName = "DummyTable")
  public class Tester {
      @Id
      private String id;
  
  
      @DynamoDBHashKey(attributeName = "id")
      public String getId() {
          return id;
      }
  
      public void setId(String id) {
          this.id = id;
      }
  }
  </code></pre>
  
  <p>The repository:</p>
  
  <pre><code>public interface TesterRepository extends CrudRepository&lt;Tester, String&gt; {
  
      @EnableScan
      @Override
      Iterable&lt;Tester&gt; findAll();
  }
  </code></pre>
  
  <p>The config class:</p>
  
  <pre><code>@Configuration
  @EnableDynamoDBRepositories(basePackages = "com.czequered.promocodes.repository")
  public class DynamoDBConfig {
  
  // deleted params
  
      @Bean
      public AmazonDynamoDB amazonDynamoDB() {
  // deleted the simple initializer, just long code
          return amazonDB;
      }
  
  }
  </code></pre>
  
  <p>And gradle dependencies:</p>
  
  <pre><code>compile 'com.amazonaws:aws-java-sdk-core:1.11.86'
  compile 'org.springframework.boot:spring-boot-starter'
  compile 'org.springframework.boot:spring-boot-starter-data-rest'
  compile 'com.github.derjust:spring-data-dynamodb:4.4.1'
  </code></pre>
  
  <p>The code has been simplified, the rest can be found in this <a href="https://gist.github.com/sm4/182a11b3feb829e466c8e7e89887ad05" rel="noreferrer">gist with all files needed to build the whole application</a>.</p>
  
  <p><a href="https://github.com/michaellavelle/spring-data-dynamodb-demo" rel="noreferrer">I tried to follow the demo from the original author of the Spring Data DynamoDB library</a>, but it adds JPA and Hibernate to the classpath which I want to avoid as I should not need any of it.</p>