|
53 | 53 | import org.springframework.data.annotation.ReadOnlyProperty;
|
54 | 54 | import org.springframework.data.annotation.Version;
|
55 | 55 | import org.springframework.data.domain.PageRequest;
|
| 56 | +import org.springframework.data.domain.Persistable; |
56 | 57 | import org.springframework.data.domain.Sort;
|
57 | 58 | import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
|
58 | 59 | import org.springframework.data.jdbc.core.convert.JdbcConverter;
|
@@ -258,14 +259,15 @@ void saveAndLoadManyEntitiesWithReferencedEntitySortedAndPaged() {
|
258 | 259 | }
|
259 | 260 |
|
260 | 261 | @Test // GH-821
|
261 |
| - @EnabledOnFeature({SUPPORTS_QUOTED_IDS, SUPPORTS_NULL_PRECEDENCE}) |
| 262 | + @EnabledOnFeature({ SUPPORTS_QUOTED_IDS, SUPPORTS_NULL_PRECEDENCE }) |
262 | 263 | void saveAndLoadManyEntitiesWithReferencedEntitySortedWithNullPrecedence() {
|
263 | 264 |
|
264 | 265 | template.save(createLegoSet(null));
|
265 | 266 | template.save(createLegoSet("Star"));
|
266 | 267 | template.save(createLegoSet("Frozen"));
|
267 | 268 |
|
268 |
| - Iterable<LegoSet> reloadedLegoSets = template.findAll(LegoSet.class, Sort.by(new Sort.Order(Sort.Direction.ASC, "name", Sort.NullHandling.NULLS_LAST))); |
| 269 | + Iterable<LegoSet> reloadedLegoSets = template.findAll(LegoSet.class, |
| 270 | + Sort.by(new Sort.Order(Sort.Direction.ASC, "name", Sort.NullHandling.NULLS_LAST))); |
269 | 271 |
|
270 | 272 | assertThat(reloadedLegoSets) //
|
271 | 273 | .extracting("name") //
|
@@ -843,7 +845,8 @@ void testUpdateEntityWithVersionDoesNotTriggerAnewConstructorInvocation() {
|
843 | 845 | assertThat(updatedRoot.version).isEqualTo(1L);
|
844 | 846 |
|
845 | 847 | // Expect only one assignment of the version to AggregateWithImmutableVersion
|
846 |
| - assertThat(AggregateWithImmutableVersion.constructorInvocations).containsOnly(new ConstructorInvocation(savedRoot.id, updatedRoot.version)); |
| 848 | + assertThat(AggregateWithImmutableVersion.constructorInvocations) |
| 849 | + .containsOnly(new ConstructorInvocation(savedRoot.id, updatedRoot.version)); |
847 | 850 | }
|
848 | 851 |
|
849 | 852 | @Test // DATAJDBC-219 Test that a delete with a version attribute works as expected.
|
@@ -908,6 +911,16 @@ void saveAndUpdateAggregateWithPrimitiveShortVersion() {
|
908 | 911 | saveAndUpdateAggregateWithPrimitiveVersion(new AggregateWithPrimitiveShortVersion(), Number::shortValue);
|
909 | 912 | }
|
910 | 913 |
|
| 914 | + @Test // GH-1254 |
| 915 | + void saveAndUpdateAggregateWithIdAndNullVersion() { |
| 916 | + |
| 917 | + PersistableVersionedAggregate aggregate = new PersistableVersionedAggregate(); |
| 918 | + aggregate.setVersion(null); |
| 919 | + aggregate.setId(23L); |
| 920 | + |
| 921 | + assertThatThrownBy(() -> template.save(aggregate)).isInstanceOf(DbActionExecutionException.class); |
| 922 | + } |
| 923 | + |
911 | 924 | @Test // DATAJDBC-462
|
912 | 925 | @EnabledOnFeature(SUPPORTS_QUOTED_IDS)
|
913 | 926 | void resavingAnUnversionedEntity() {
|
@@ -1075,18 +1088,15 @@ static class ListParent {
|
1075 | 1088 |
|
1076 | 1089 | @Column("id4") @Id private Long id;
|
1077 | 1090 | String name;
|
1078 |
| - @MappedCollection(idColumn = "LIST_PARENT") |
1079 |
| - List<ElementNoId> content = new ArrayList<>(); |
| 1091 | + @MappedCollection(idColumn = "LIST_PARENT") List<ElementNoId> content = new ArrayList<>(); |
1080 | 1092 | }
|
1081 | 1093 |
|
1082 | 1094 | @Table("LIST_PARENT")
|
1083 | 1095 | static class ListParentAllArgs {
|
1084 | 1096 |
|
1085 |
| - @Column("id4") @Id |
1086 |
| - private final Long id; |
| 1097 | + @Column("id4") @Id private final Long id; |
1087 | 1098 | private final String name;
|
1088 |
| - @MappedCollection(idColumn = "LIST_PARENT") |
1089 |
| - private final List<ElementNoId> content = new ArrayList<>(); |
| 1099 | + @MappedCollection(idColumn = "LIST_PARENT") private final List<ElementNoId> content = new ArrayList<>(); |
1090 | 1100 |
|
1091 | 1101 | @PersistenceConstructor
|
1092 | 1102 | ListParentAllArgs(Long id, String name, List<ElementNoId> content) {
|
@@ -1247,6 +1257,20 @@ static abstract class VersionedAggregate {
|
1247 | 1257 | abstract void setVersion(Number newVersion);
|
1248 | 1258 | }
|
1249 | 1259 |
|
| 1260 | + @Data |
| 1261 | + @Table("VERSIONED_AGGREGATE") |
| 1262 | + static class PersistableVersionedAggregate implements Persistable<Long> { |
| 1263 | + |
| 1264 | + @Id private Long id; |
| 1265 | + |
| 1266 | + @Version Long version; |
| 1267 | + |
| 1268 | + @Override |
| 1269 | + public boolean isNew() { |
| 1270 | + return getId() == null; |
| 1271 | + } |
| 1272 | + } |
| 1273 | + |
1250 | 1274 | @Value
|
1251 | 1275 | @With
|
1252 | 1276 | @Table("VERSIONED_AGGREGATE")
|
|
0 commit comments