Skip to content

Commit b79b302

Browse files
Fix for bulk saving multiple auto id entitites
1 parent 4710ecb commit b79b302

File tree

3 files changed

+25
-2
lines changed
  • spring-data-eclipse-store/src

3 files changed

+25
-2
lines changed

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/id/IdManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public <S extends T> void checkIds(final Collection<S> entities)
147147
}
148148

149149
final List<ID> multipleEqualIds = ids.stream()
150-
.filter(id -> Collections.frequency(ids, id) > 1)
150+
.filter(id -> id != null && Collections.frequency(ids, id) > 1)
151151
.toList();
152152
if(!multipleEqualIds.isEmpty())
153153
{

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/id/SimpleIdSetter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void ensureId(final T objectToSetIdIn)
6161
final Object existingId = fam.getValueOfField(objectToSetIdIn);
6262
if(existingId == null)
6363
{
64-
final ID newId = (ID)this.idFinder.findId();
64+
final ID newId = this.idFinder.findId();
6565
fam.writeValueOfField(objectToSetIdIn, newId, true);
6666
this.lastIdPersister.accept(newId);
6767
}

spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/id/IdTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,29 @@ void testCreateSingleWithAutoIdInteger(@Autowired final CustomerWithIdIntegerRep
7575
);
7676
}
7777

78+
@Test
79+
void saveBulkWithAutoIdInteger(@Autowired final CustomerWithIdIntegerRepository customerRepository)
80+
{
81+
final CustomerWithIdInteger customer1 = new CustomerWithIdInteger(TestData.FIRST_NAME, TestData.LAST_NAME);
82+
final CustomerWithIdInteger customer2 = new CustomerWithIdInteger(TestData.FIRST_NAME, TestData.LAST_NAME);
83+
customerRepository.saveAll(List.of(customer1, customer2));
84+
85+
TestUtil.doBeforeAndAfterRestartOfDatastore(
86+
this.configuration,
87+
() -> {
88+
Assertions.assertEquals(2, customerRepository.count());
89+
90+
final Optional<CustomerWithIdInteger> loadedCustomer1 = customerRepository.findById(0);
91+
Assertions.assertTrue(loadedCustomer1.isPresent());
92+
Assertions.assertEquals(customer1, loadedCustomer1.get());
93+
94+
final Optional<CustomerWithIdInteger> loadedCustomer2 = customerRepository.findById(1);
95+
Assertions.assertTrue(loadedCustomer2.isPresent());
96+
Assertions.assertEquals(customer2, loadedCustomer2.get());
97+
}
98+
);
99+
}
100+
78101
/**
79102
* In other tests {@link EclipseStoreStorage#clearData} is called. Here the datastore is restarted again to ensure
80103
* no previous method is called before the test.

0 commit comments

Comments
 (0)