|
50 | 50 | import org.springframework.beans.factory.annotation.Autowired;
|
51 | 51 | import org.springframework.dao.DataAccessException;
|
52 | 52 | import org.springframework.dao.OptimisticLockingFailureException;
|
| 53 | +import org.springframework.data.annotation.AccessType; |
53 | 54 | import org.springframework.data.annotation.Id;
|
| 55 | +import org.springframework.data.annotation.ReadOnlyProperty; |
54 | 56 | import org.springframework.data.annotation.Version;
|
55 | 57 | import org.springframework.data.domain.PageRequest;
|
56 | 58 | import org.springframework.data.domain.Pageable;
|
@@ -1161,6 +1163,23 @@ void shouldReturnMonoOfReactiveSearchHits() {
|
1161 | 1163 | .verifyComplete();
|
1162 | 1164 | }
|
1163 | 1165 |
|
| 1166 | + @Test // #2230 |
| 1167 | + @DisplayName("should work with readonly id") |
| 1168 | + void shouldWorkWithReadonlyId() { |
| 1169 | + |
| 1170 | + ReadonlyIdEntity entity = new ReadonlyIdEntity(); |
| 1171 | + entity.setPart1("foo"); |
| 1172 | + entity.setPart2("bar"); |
| 1173 | + |
| 1174 | + operations.save(entity).block(); |
| 1175 | + |
| 1176 | + operations.get(entity.getId(), ReadonlyIdEntity.class) // |
| 1177 | + .as(StepVerifier::create) // |
| 1178 | + .assertNext(readEntity -> { // |
| 1179 | + assertThat(readEntity.getPart1()).isEqualTo(entity.getPart1()); // |
| 1180 | + assertThat(readEntity.getPart2()).isEqualTo(entity.getPart2()); // |
| 1181 | + }).verifyComplete(); |
| 1182 | + } |
1164 | 1183 | // endregion
|
1165 | 1184 |
|
1166 | 1185 | // region Helper functions
|
@@ -1494,5 +1513,35 @@ public String toString() {
|
1494 | 1513 | + seqNoPrimaryTerm + '}';
|
1495 | 1514 | }
|
1496 | 1515 | }
|
| 1516 | + |
| 1517 | + @Document(indexName = "#{@indexNameProvider.indexName()}-readonly-id") |
| 1518 | + static class ReadonlyIdEntity { |
| 1519 | + @Field(type = FieldType.Keyword) private String part1; |
| 1520 | + |
| 1521 | + @Field(type = FieldType.Keyword) private String part2; |
| 1522 | + |
| 1523 | + @Id |
| 1524 | + @ReadOnlyProperty |
| 1525 | + @AccessType(AccessType.Type.PROPERTY) |
| 1526 | + public String getId() { |
| 1527 | + return part1 + '-' + part2; |
| 1528 | + } |
| 1529 | + |
| 1530 | + public String getPart1() { |
| 1531 | + return part1; |
| 1532 | + } |
| 1533 | + |
| 1534 | + public void setPart1(String part1) { |
| 1535 | + this.part1 = part1; |
| 1536 | + } |
| 1537 | + |
| 1538 | + public String getPart2() { |
| 1539 | + return part2; |
| 1540 | + } |
| 1541 | + |
| 1542 | + public void setPart2(String part2) { |
| 1543 | + this.part2 = part2; |
| 1544 | + } |
| 1545 | + } |
1497 | 1546 | // endregion
|
1498 | 1547 | }
|
0 commit comments