title: DynamoDBMapper load vs query
body: <p>The DynamoDBMapper provides different ways to read one item from a table:</p>
  
  <ul>
  <li>query</li>
  <li>load</li>
  </ul>
  
  <p>Is there a recommendation, which of them to use? In a quick test, the following two code snippets return the same "MyEntry" item for a table with primary key=hash and range key=date, whereas the query method is roughly 10% faster.</p>
  
  <p><strong>load</strong></p>
  
  
  
  <pre class="lang-java prettyprint-override"><code>public MyEntry getEntryForDay(final Integer hash, final LocalDate date) {
      return mapper.load(MyEntry.class, hash, date);
  }
  </code></pre>
  
  <p><strong>query</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>public MyEntry getEntryForDay(final Integer hash, final LocalDate date) {
      final MyEntry hashKeyValues = new MyEntry ();
      hashKeyValues.setHash(hash);
      final Condition rangeKeyCondition = new Condition()//
              .withComparisonOperator(ComparisonOperator.EQ.toString())//
              .withAttributeValueList(new AttributeValue().withS(new LocalDateMarshaller().marshall(date)));
      final DynamoDBQueryExpression&lt;MyEntry&gt; queryExpression = new DynamoDBQueryExpression&lt;MyEntry&gt;()//
              .withHashKeyValues(hashKeyValues)//
              .withRangeKeyCondition("date", rangeKeyCondition)//
              .withLimit(1);
      final List&lt;MyEntry&gt; storedEntries = mapper
              .query(MyEntry.class, queryExpression);
      if (storedEntries.size() == 0) {
          return null;
      }
      return storedEntries.get(0);
  }
  </code></pre>