title: Querying Tables with Composite Primary Keys using Spring-data-cassandra
body: <p>I'm getting the following exception when using the findOne() or findAll() method of CassandraReporitory:</p>
  
  <pre><code>Caused by: java.lang.IllegalStateException: property does not have a single column mapping
      at org.springframework.data.cassandra.mapping.BasicCassandraPersistentProperty.getColumnName(BasicCassandraPersistentProperty.java:134)
      at org.springframework.data.cassandra.convert.BasicCassandraRowValueProvider.getPropertyValue(BasicCassandraRowValueProvider.java:64)
      at org.springframework.data.cassandra.convert.BasicCassandraRowValueProvider.getPropertyValue(BasicCassandraRowValueProvider.java:35)
      at org.springframework.data.mapping.model.PersistentEntityParameterValueProvider.getParameterValue(PersistentEntityParameterValueProvider.java:78)
      at org.springframework.data.convert.ReflectionEntityInstantiator.createInstance(ReflectionEntityInstantiator.java:71)
      at org.springframework.data.convert.ClassGeneratingEntityInstantiator.createInstance(ClassGeneratingEntityInstantiator.java:83)
      at org.springframework.data.cassandra.convert.MappingCassandraConverter.readEntityFromRow(MappingCassandraConverter.java:133)
      at org.springframework.data.cassandra.convert.MappingCassandraConverter.readRow(MappingCassandraConverter.java:115)
      at org.springframework.data.cassandra.convert.MappingCassandraConverter.read(MappingCassandraConverter.java:200)
      at org.springframework.data.cassandra.repository.query.AbstractCassandraQuery.getSingleEntity(AbstractCassandraQuery.java:176)
      at org.springframework.data.cassandra.repository.query.AbstractCassandraQuery.execute(AbstractCassandraQuery.java:133)
      at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:454)
      at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:432)
  </code></pre>
  
  <p>My class definitions are as follows:</p>
  
  <pre><code>@PrimaryKeyClass
  public class ItemAndLocationKey implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      @PrimaryKeyColumn(name = "itemId", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
      @CassandraType(type = Name.UUID)
      private UUID itemId;
      @PrimaryKeyColumn(name = "locationId", ordinal = 1, type = PrimaryKeyType.CLUSTERED)
      @CassandraType(type = Name.UUID)
      private UUID locationId;
  
      public ItemAndLocationKey(UUID itemId, UUID locationId) {
          this.itemId = itemId;
          this.locationId = locationId;
      }
  
      public UUID getItemId() {
          return itemId;
      }
  
      public void setItemId(UUID itemId) {
          this.itemId = itemId;
      }
  
      public UUID getLocationId() {
          return locationId;
      }
  
      public void setLocationId(UUID locationId) {
          this.locationId = locationId;
      }
  
      @Override
      public boolean equals(Object o) {
          if (this == o) return true;
          if (o == null || getClass() != o.getClass()) return false;
  
          ItemAndLocationKey that = (ItemAndLocationKey) o;
  
          if (!itemId.equals(that.itemId)) return false;
          return locationId.equals(that.locationId);
      }
  
      @Override
      public int hashCode() {
          final int prime = 31;
          int result = 1;
          result = prime * result + itemId.hashCode();
          result = prime * result + locationId.hashCode();
          return result;
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>@Table(value = ItemAndLocation.tableName)
  public class ItemAndLocation {
  
      @org.springframework.data.annotation.Transient
      public static final String tableName = "ItemAndLocation";
  
      @PrimaryKey
      private ItemAndLocationKey itemAndLocationKey;
  
      public ItemAndLocation(ItemAndLocationKey itemAndLocationKey) {
          this.itemAndLocationKey = itemAndLocationKey;
      }
  
      public ItemAndLocationKey getItemAndLocationKey() {
          return itemAndLocationKey;
      }
  
      public void setItemAndLocationKey(ItemAndLocationKey itemAndLocationKey) {
          this.itemAndLocationKey = itemAndLocationKey;
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public interface ItemAndLocationRepository extends TypedIdCassandraRepository&lt;ItemAndLocation, ItemAndLocationKey&gt; {
  
  }
  </code></pre>
  
  <hr>
  
  <p>Essentially what is happening here is that after reading a row from Cassandra during the invocation of findOne() or findAll(), spring data cassandra attempts to use ClassGeneratingEntityInstantiator to instantiate the ItemAndLocation object that does not know how to populate the composite primary key object, ItemAndLocationKey. I couldn't figure out how to supply a custom object instantiator. There are no examples or documentation for the current release.</p>
  
  <p>Any help will be much appreciated.</p>