I have following entity
@Entity
@Data
public class Book {
@Id
Long id;
String title;
@Reference
Set chapters = new HashSet<>();
}
if I search books with title using Example.of query (not setting any value for chapters), I am getting below error
com.google.cloud.spring.data.datastore.core.mapping.DatastoreDataException: An ID property was required but does not exist for the type: class java.util.HashSet
at com.google.cloud.spring.data.datastore.core.mapping.DatastorePersistentEntityImpl.getIdPropertyOrFail(DatastorePersistentEntityImpl.java:135)
at com.example.demo.keys.SaccObjectToKeyFactory.getKeyFromObject(SaccObjectToKeyFactory.java:64)
at com.google.cloud.spring.data.datastore.core.DatastoreTemplate.lambda$exampleToQuery$22(DatastoreTemplate.java:923)
at org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociations(BasicPersistentEntity.java:317)
at com.google.cloud.spring.data.datastore.core.DatastoreTemplate.exampleToQuery(DatastoreTemplate.java:912)
at com.google.cloud.spring.data.datastore.core.DatastoreTemplate.queryByExample(DatastoreTemplate.java:390)
at com.google.cloud.spring.data.datastore.core.DatastoreTemplate.queryByExample(DatastoreTemplate.java:100)
at com.google.cloud.spring.data.datastore.repository.support.SimpleDatastoreRepository.findAll(SimpleDatastoreRepository.java:189)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
I believe root cause is at below location
com.google.cloud.spring.data.datastore.core.DatastoreTemplate.exampleToQuery(Example, DatastoreQueryOptions, boolean)
I have following entity @Entity @Data public class Book { @Id Long id; String title; @Reference Set chapters = new HashSet<>();
}
if I search books with title using Example.of query (not setting any value for chapters), I am getting below error
com.google.cloud.spring.data.datastore.core.mapping.DatastoreDataException: An ID property was required but does not exist for the type: class java.util.HashSet at com.google.cloud.spring.data.datastore.core.mapping.DatastorePersistentEntityImpl.getIdPropertyOrFail(DatastorePersistentEntityImpl.java:135) at com.example.demo.keys.SaccObjectToKeyFactory.getKeyFromObject(SaccObjectToKeyFactory.java:64) at com.google.cloud.spring.data.datastore.core.DatastoreTemplate.lambda$exampleToQuery$22(DatastoreTemplate.java:923) at org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociations(BasicPersistentEntity.java:317) at com.google.cloud.spring.data.datastore.core.DatastoreTemplate.exampleToQuery(DatastoreTemplate.java:912) at com.google.cloud.spring.data.datastore.core.DatastoreTemplate.queryByExample(DatastoreTemplate.java:390) at com.google.cloud.spring.data.datastore.core.DatastoreTemplate.queryByExample(DatastoreTemplate.java:100) at com.google.cloud.spring.data.datastore.repository.support.SimpleDatastoreRepository.findAll(SimpleDatastoreRepository.java:189) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
I believe root cause is at below location com.google.cloud.spring.data.datastore.core.DatastoreTemplate.exampleToQuery(Example, DatastoreQueryOptions, boolean)
persistentEntity.doWithAssociations( (AssociationHandler)
association -> {
PersistentPropertyAccessor<?> accessor =
persistentEntity.getPropertyAccessor(example.getProbe());
DatastorePersistentProperty property = association.getInverse();
Object value = accessor.getProperty(property);
Value<?> key =
value == null
? NullValue.of()
: KeyValue.of(
objectToKeyFactory.getKeyFromObject(
value, getPersistentEntity(value.getClass())));
addFilter(nullHandler, filters, property.getFieldName(), key);
});
function check for null but do not check for empty set.