Skip to content

Commit 762071c

Browse files
committed
DATAJDBC-417 - Reproducer.
1 parent f3793a2 commit 762071c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/RelationalEntityWriterUnitTests.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,29 @@ public void newEntityGetsConvertedToOneInsertByEmbeddedEntities() {
118118
);
119119
}
120120

121+
@Test // DATAJDBC-417
122+
public void nullEmbeddedFails() {
123+
124+
EmbeddedReferenceChainEntity entity = new EmbeddedReferenceChainEntity(null);
125+
// the embedded is null !!!
126+
127+
128+
AggregateChange<EmbeddedReferenceChainEntity> aggregateChange = //
129+
new AggregateChange<>(Kind.SAVE, EmbeddedReferenceChainEntity.class, entity);
130+
131+
converter.write(entity, aggregateChange);
132+
133+
assertThat(aggregateChange.getActions()) //
134+
.extracting(DbAction::getClass, //
135+
DbAction::getEntityType, //
136+
DbActionTestSupport::extractPath, //
137+
DbActionTestSupport::actualEntityType, //
138+
DbActionTestSupport::isWithDependsOn) //
139+
.containsExactly( //
140+
tuple(InsertRoot.class, EmbeddedReferenceChainEntity.class, "", EmbeddedReferenceChainEntity.class, false) //
141+
);
142+
}
143+
121144
@Test // DATAJDBC-112
122145
public void newEntityWithReferenceGetsConvertedToTwoInserts() {
123146

@@ -585,6 +608,13 @@ static class EmbeddedReferenceEntity {
585608
@Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "prefix_") Element other;
586609
}
587610

611+
@RequiredArgsConstructor
612+
static class EmbeddedReferenceChainEntity {
613+
614+
@Id final Long id;
615+
@Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "prefix_") ElementReference other;
616+
}
617+
588618
@RequiredArgsConstructor
589619
static class ReferenceWoIdEntity {
590620

@@ -641,6 +671,11 @@ private static class Element {
641671
@Id final Long id;
642672
}
643673

674+
@RequiredArgsConstructor
675+
private static class ElementReference {
676+
final Element element;
677+
}
678+
644679
@RequiredArgsConstructor
645680
private static class NoIdListMapContainer {
646681

0 commit comments

Comments
 (0)