I'm getting the following exception when using the findOne() or findAll() method of CassandraReporitory:
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)
My class definitions are as follows:
@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;
}
}
@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;
}
}
public interface ItemAndLocationRepository extends TypedIdCassandraRepository<ItemAndLocation, ItemAndLocationKey> {
}
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.
Any help will be much appreciated.