diff --git a/src/main/java/org/springframework/data/aerospike/core/ReactiveAerospikeTemplate.java b/src/main/java/org/springframework/data/aerospike/core/ReactiveAerospikeTemplate.java index 9e011194..cc5f3ed2 100644 --- a/src/main/java/org/springframework/data/aerospike/core/ReactiveAerospikeTemplate.java +++ b/src/main/java/org/springframework/data/aerospike/core/ReactiveAerospikeTemplate.java @@ -1301,7 +1301,12 @@ private String[] getBinNamesFromTargetClass(Class targetClass) { List binNamesList = new ArrayList<>(); targetEntity.doWithProperties( - (PropertyHandler) property -> binNamesList.add(property.getFieldName())); + (PropertyHandler) property -> { + if (!property.isIdProperty()) { + binNamesList.add(property.getFieldName()); + } + } + ); return binNamesList.toArray(new String[0]); } diff --git a/src/main/java/org/springframework/data/aerospike/core/TemplateUtils.java b/src/main/java/org/springframework/data/aerospike/core/TemplateUtils.java index d2c4abc6..9f2d9f0a 100644 --- a/src/main/java/org/springframework/data/aerospike/core/TemplateUtils.java +++ b/src/main/java/org/springframework/data/aerospike/core/TemplateUtils.java @@ -106,8 +106,12 @@ public static String[] getBinNamesFromTargetClass(Class targetClass, List binNamesList = new ArrayList<>(); - targetEntity.doWithProperties((PropertyHandler) property - -> binNamesList.add(property.getFieldName())); + targetEntity.doWithProperties( + (PropertyHandler) property -> { + if (!property.isIdProperty()) { + binNamesList.add(property.getFieldName()); + } + }); return binNamesList.toArray(new String[0]); } diff --git a/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindAllTests.java b/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindAllTests.java index 646df790..018180b2 100644 --- a/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindAllTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindAllTests.java @@ -3,6 +3,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import org.springframework.data.aerospike.sample.Person; +import org.springframework.data.aerospike.sample.SampleClasses; import reactor.core.scheduler.Schedulers; import java.util.List; @@ -52,4 +53,24 @@ public void findAll_findNothing() { assertThat(actual).isEmpty(); } + + @Test + public void findAll_findIdOnlyRecord() { + var id = 100; + var doc = new SampleClasses.DocumentWithPrimitiveIntId(id); // id-only document + var clazz = SampleClasses.DocumentWithPrimitiveIntId.class; + + var existingDoc = reactiveTemplate.findById(id, clazz).block(); + assertThat(existingDoc).withFailMessage("The same record already exists").isNull(); + + reactiveTemplate.insert(doc).block(); + var resultsFindById = reactiveTemplate.findById(id, clazz).block(); + assertThat(resultsFindById).withFailMessage("findById error").isEqualTo(doc); + var resultsFindAll = reactiveTemplate.findAll(clazz).collectList().block(); + // findAll() must correctly find the record that contains id and no bins + assertThat(resultsFindAll).size().withFailMessage("findAll error").isEqualTo(1); + + // cleanup + reactiveTemplate.delete(doc); + } } diff --git a/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindAllTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindAllTests.java index 345c79b0..a39e84ea 100644 --- a/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindAllTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindAllTests.java @@ -18,6 +18,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import org.springframework.data.aerospike.sample.Person; +import org.springframework.data.aerospike.sample.SampleClasses; import org.springframework.data.domain.Sort; import java.util.List; @@ -65,6 +66,7 @@ public void findAll_findNothing() { Stream result = template.findAll(Person.class); assertThat(result).isEmpty(); + // bring records back // batch write operations are supported starting with Server version 6.0+ if (serverVersionSupport.isBatchWriteSupported()) { template.insertAll(allPersons); @@ -72,4 +74,24 @@ public void findAll_findNothing() { allPersons.forEach(person -> template.insert(person)); } } + + @Test + public void findAll_findIdOnlyRecord() { + var id = 100; + var doc = new SampleClasses.DocumentWithPrimitiveIntId(id); // id-only document + var clazz = SampleClasses.DocumentWithPrimitiveIntId.class; + + var existingDoc = template.findById(id, clazz); + assertThat(existingDoc).withFailMessage("The same record already exists").isNull(); + + template.insert(doc); + var resultsFindById = template.findById(id, clazz); + assertThat(resultsFindById).withFailMessage("findById error").isEqualTo(doc); + var resultsFindAll = template.findAll(clazz); + // findAll() must correctly find the record that contains id and no bins + assertThat(resultsFindAll.toList()).size().withFailMessage("findAll error").isEqualTo(1); + + // cleanup + template.delete(doc); + } }