|
54 | 54 | import org.springframework.data.annotation.ReadOnlyProperty;
|
55 | 55 | import org.springframework.data.annotation.Version;
|
56 | 56 | import org.springframework.data.domain.PageRequest;
|
| 57 | +import org.springframework.data.domain.Persistable; |
57 | 58 | import org.springframework.data.domain.Sort;
|
58 | 59 | import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
|
59 | 60 | import org.springframework.data.jdbc.core.convert.JdbcConverter;
|
@@ -278,7 +279,8 @@ void saveAndLoadManyEntitiesWithReferencedEntitySortedWithNullPrecedence() {
|
278 | 279 | template.save(createLegoSet("Star"));
|
279 | 280 | template.save(createLegoSet("Frozen"));
|
280 | 281 |
|
281 |
| - final Sort sort = Sort.by(new Sort.Order(Sort.Direction.ASC, "name", Sort.NullHandling.NULLS_LAST)); |
| 282 | + final Sort sort = |
| 283 | + Sort.by(new Sort.Order(Sort.Direction.ASC, "name", Sort.NullHandling.NULLS_LAST)); |
282 | 284 | Iterable<LegoSet> reloadedLegoSets = template.findAll(LegoSet.class, sort);
|
283 | 285 |
|
284 | 286 | assertThat(reloadedLegoSets) //
|
@@ -923,6 +925,16 @@ void saveAndUpdateAggregateWithPrimitiveShortVersion() {
|
923 | 925 | saveAndUpdateAggregateWithPrimitiveVersion(new AggregateWithPrimitiveShortVersion(), Number::shortValue);
|
924 | 926 | }
|
925 | 927 |
|
| 928 | + @Test // GH-1254 |
| 929 | + void saveAndUpdateAggregateWithIdAndNullVersion() { |
| 930 | + |
| 931 | + PersistableVersionedAggregate aggregate = new PersistableVersionedAggregate(); |
| 932 | + aggregate.setVersion(null); |
| 933 | + aggregate.setId(23L); |
| 934 | + |
| 935 | + assertThatThrownBy(() -> template.save(aggregate)).isInstanceOf(DbActionExecutionException.class); |
| 936 | + } |
| 937 | + |
926 | 938 | @Test // DATAJDBC-462
|
927 | 939 | @EnabledOnFeature(SUPPORTS_QUOTED_IDS)
|
928 | 940 | void resavingAnUnversionedEntity() {
|
@@ -1115,18 +1127,15 @@ static class ListParent {
|
1115 | 1127 |
|
1116 | 1128 | @Column("id4") @Id private Long id;
|
1117 | 1129 | String name;
|
1118 |
| - @MappedCollection(idColumn = "LIST_PARENT") |
1119 |
| - List<ElementNoId> content = new ArrayList<>(); |
| 1130 | + @MappedCollection(idColumn = "LIST_PARENT") List<ElementNoId> content = new ArrayList<>(); |
1120 | 1131 | }
|
1121 | 1132 |
|
1122 | 1133 | @Table("LIST_PARENT")
|
1123 | 1134 | static class ListParentAllArgs {
|
1124 | 1135 |
|
1125 |
| - @Column("id4") @Id |
1126 |
| - private final Long id; |
| 1136 | + @Column("id4") @Id private final Long id; |
1127 | 1137 | private final String name;
|
1128 |
| - @MappedCollection(idColumn = "LIST_PARENT") |
1129 |
| - private final List<ElementNoId> content = new ArrayList<>(); |
| 1138 | + @MappedCollection(idColumn = "LIST_PARENT") private final List<ElementNoId> content = new ArrayList<>(); |
1130 | 1139 |
|
1131 | 1140 | @PersistenceConstructor
|
1132 | 1141 | ListParentAllArgs(Long id, String name, List<ElementNoId> content) {
|
@@ -1287,6 +1296,20 @@ static abstract class VersionedAggregate {
|
1287 | 1296 | abstract void setVersion(Number newVersion);
|
1288 | 1297 | }
|
1289 | 1298 |
|
| 1299 | + @Data |
| 1300 | + @Table("VERSIONED_AGGREGATE") |
| 1301 | + static class PersistableVersionedAggregate implements Persistable<Long> { |
| 1302 | + |
| 1303 | + @Id private Long id; |
| 1304 | + |
| 1305 | + @Version Long version; |
| 1306 | + |
| 1307 | + @Override |
| 1308 | + public boolean isNew() { |
| 1309 | + return getId() == null; |
| 1310 | + } |
| 1311 | + } |
| 1312 | + |
1290 | 1313 | @Value
|
1291 | 1314 | @With
|
1292 | 1315 | @Table("VERSIONED_AGGREGATE")
|
|
0 commit comments