|
29 | 29 | import org.junit.Test;
|
30 | 30 | import org.junit.runner.RunWith;
|
31 | 31 | import org.mockito.junit.MockitoJUnitRunner;
|
32 |
| - |
33 | 32 | import org.springframework.data.annotation.Id;
|
34 | 33 | import org.springframework.data.mapping.PersistentPropertyPath;
|
35 | 34 | import org.springframework.data.mapping.PersistentPropertyPaths;
|
@@ -118,6 +117,7 @@ public void newEntityGetsConvertedToOneInsertByEmbeddedEntities() {
|
118 | 117 | );
|
119 | 118 | }
|
120 | 119 |
|
| 120 | + |
121 | 121 | @Test // DATAJDBC-112
|
122 | 122 | public void newEntityWithReferenceGetsConvertedToTwoInserts() {
|
123 | 123 |
|
@@ -530,6 +530,51 @@ public void multiLevelQualifiedReferencesWithOutId() {
|
530 | 530 | );
|
531 | 531 | }
|
532 | 532 |
|
| 533 | + @Test // DATAJDBC-417 |
| 534 | + public void savingANullEmbeddedWithEntity() { |
| 535 | + |
| 536 | + EmbeddedReferenceChainEntity entity = new EmbeddedReferenceChainEntity(null); |
| 537 | + // the embedded is null !!! |
| 538 | + |
| 539 | + AggregateChange<EmbeddedReferenceChainEntity> aggregateChange = // |
| 540 | + new AggregateChange<>(Kind.SAVE, EmbeddedReferenceChainEntity.class, entity); |
| 541 | + |
| 542 | + converter.write(entity, aggregateChange); |
| 543 | + |
| 544 | + assertThat(aggregateChange.getActions()) // |
| 545 | + .extracting(DbAction::getClass, // |
| 546 | + DbAction::getEntityType, // |
| 547 | + DbActionTestSupport::extractPath, // |
| 548 | + DbActionTestSupport::actualEntityType, // |
| 549 | + DbActionTestSupport::isWithDependsOn) // |
| 550 | + .containsExactly( // |
| 551 | + tuple(InsertRoot.class, EmbeddedReferenceChainEntity.class, "", EmbeddedReferenceChainEntity.class, false) // |
| 552 | + ); |
| 553 | + } |
| 554 | + @Test // DATAJDBC-417 |
| 555 | + public void savingInnerNullEmbeddedWithEntity() { |
| 556 | + |
| 557 | + RootWithEmbeddedReferenceChainEntity root = new RootWithEmbeddedReferenceChainEntity(null); |
| 558 | + root.other = new EmbeddedReferenceChainEntity(null); |
| 559 | + // the embedded is null !!! |
| 560 | + |
| 561 | + AggregateChange<RootWithEmbeddedReferenceChainEntity> aggregateChange = // |
| 562 | + new AggregateChange<>(Kind.SAVE, RootWithEmbeddedReferenceChainEntity.class, root); |
| 563 | + |
| 564 | + converter.write(root, aggregateChange); |
| 565 | + |
| 566 | + assertThat(aggregateChange.getActions()) // |
| 567 | + .extracting(DbAction::getClass, // |
| 568 | + DbAction::getEntityType, // |
| 569 | + DbActionTestSupport::extractPath, // |
| 570 | + DbActionTestSupport::actualEntityType, // |
| 571 | + DbActionTestSupport::isWithDependsOn) // |
| 572 | + .containsExactly( // |
| 573 | + tuple(InsertRoot.class, RootWithEmbeddedReferenceChainEntity.class, "", RootWithEmbeddedReferenceChainEntity.class, false), // |
| 574 | + tuple(Insert.class, EmbeddedReferenceChainEntity.class, "other", EmbeddedReferenceChainEntity.class, true) // |
| 575 | + ); |
| 576 | + } |
| 577 | + |
533 | 578 | private CascadingReferenceMiddleElement createMiddleElement(Element first, Element second) {
|
534 | 579 |
|
535 | 580 | CascadingReferenceMiddleElement middleElement1 = new CascadingReferenceMiddleElement(null);
|
@@ -585,6 +630,19 @@ static class EmbeddedReferenceEntity {
|
585 | 630 | @Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "prefix_") Element other;
|
586 | 631 | }
|
587 | 632 |
|
| 633 | + @RequiredArgsConstructor |
| 634 | + static class EmbeddedReferenceChainEntity { |
| 635 | + |
| 636 | + @Id final Long id; |
| 637 | + @Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "prefix_") ElementReference other; |
| 638 | + } |
| 639 | + @RequiredArgsConstructor |
| 640 | + static class RootWithEmbeddedReferenceChainEntity { |
| 641 | + |
| 642 | + @Id final Long id; |
| 643 | + EmbeddedReferenceChainEntity other; |
| 644 | + } |
| 645 | + |
588 | 646 | @RequiredArgsConstructor
|
589 | 647 | static class ReferenceWoIdEntity {
|
590 | 648 |
|
@@ -641,6 +699,11 @@ private static class Element {
|
641 | 699 | @Id final Long id;
|
642 | 700 | }
|
643 | 701 |
|
| 702 | + @RequiredArgsConstructor |
| 703 | + private static class ElementReference { |
| 704 | + final Element element; |
| 705 | + } |
| 706 | + |
644 | 707 | @RequiredArgsConstructor
|
645 | 708 | private static class NoIdListMapContainer {
|
646 | 709 |
|
|
0 commit comments