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