Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>1.2.0.BUILD-SNAPSHOT</version>
<version>1.2.0.DATAJDBC-417-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data Relational Parent</name>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-jdbc-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>1.2.0.BUILD-SNAPSHOT</version>
<version>1.2.0.DATAJDBC-417-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions spring-data-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-jdbc</artifactId>
<version>1.2.0.BUILD-SNAPSHOT</version>
<version>1.2.0.DATAJDBC-417-SNAPSHOT</version>

<name>Spring Data JDBC</name>
<description>Spring Data module for JDBC repositories.</description>
Expand All @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>1.2.0.BUILD-SNAPSHOT</version>
<version>1.2.0.DATAJDBC-417-SNAPSHOT</version>
</parent>

<properties>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-relational/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-relational</artifactId>
<version>1.2.0.BUILD-SNAPSHOT</version>
<version>1.2.0.DATAJDBC-417-SNAPSHOT</version>

<name>Spring Data Relational</name>
<description>Spring Data Relational support</description>

<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>1.2.0.BUILD-SNAPSHOT</version>
<version>1.2.0.DATAJDBC-417-SNAPSHOT</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ private List<PathNode> from(PersistentPropertyPath<RelationalPersistentProperty>

} else {

List<PathNode> pathNodes = nodesCache.get(path.getParentPath());
List<PathNode> pathNodes = nodesCache.getOrDefault(path.getParentPath(), Collections.emptyList());

pathNodes.forEach(parentNode -> {

// todo: this should go into pathnode
Expand Down Expand Up @@ -238,7 +239,17 @@ private boolean isDirectlyReferencedByRootIgnoringEmbeddables(

@Nullable
private Object getFromRootValue(PersistentPropertyPath<RelationalPersistentProperty> path) {
return path.getBaseProperty().getOwner().getPropertyAccessor(entity).getProperty(path);

if (path.getLength() == 0)
return entity;

Object parent = getFromRootValue(path.getParentPath());
if (parent == null) {
return null;
}

return context.getRequiredPersistentEntity(parent.getClass()).getPropertyAccessor(parent)
.getProperty(path.getRequiredLeafProperty());
}

private List<PathNode> createNodes(PersistentPropertyPath<RelationalPersistentProperty> path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

import org.springframework.data.annotation.Id;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.mapping.PersistentPropertyPaths;
Expand Down Expand Up @@ -118,6 +117,7 @@ public void newEntityGetsConvertedToOneInsertByEmbeddedEntities() {
);
}


@Test // DATAJDBC-112
public void newEntityWithReferenceGetsConvertedToTwoInserts() {

Expand Down Expand Up @@ -530,6 +530,51 @@ public void multiLevelQualifiedReferencesWithOutId() {
);
}

@Test // DATAJDBC-417
public void savingANullEmbeddedWithEntity() {

EmbeddedReferenceChainEntity entity = new EmbeddedReferenceChainEntity(null);
// the embedded is null !!!

AggregateChange<EmbeddedReferenceChainEntity> aggregateChange = //
new AggregateChange<>(Kind.SAVE, EmbeddedReferenceChainEntity.class, entity);

converter.write(entity, aggregateChange);

assertThat(aggregateChange.getActions()) //
.extracting(DbAction::getClass, //
DbAction::getEntityType, //
DbActionTestSupport::extractPath, //
DbActionTestSupport::actualEntityType, //
DbActionTestSupport::isWithDependsOn) //
.containsExactly( //
tuple(InsertRoot.class, EmbeddedReferenceChainEntity.class, "", EmbeddedReferenceChainEntity.class, false) //
);
}
@Test // DATAJDBC-417
public void savingInnerNullEmbeddedWithEntity() {

RootWithEmbeddedReferenceChainEntity root = new RootWithEmbeddedReferenceChainEntity(null);
root.other = new EmbeddedReferenceChainEntity(null);
// the embedded is null !!!

AggregateChange<RootWithEmbeddedReferenceChainEntity> aggregateChange = //
new AggregateChange<>(Kind.SAVE, RootWithEmbeddedReferenceChainEntity.class, root);

converter.write(root, aggregateChange);

assertThat(aggregateChange.getActions()) //
.extracting(DbAction::getClass, //
DbAction::getEntityType, //
DbActionTestSupport::extractPath, //
DbActionTestSupport::actualEntityType, //
DbActionTestSupport::isWithDependsOn) //
.containsExactly( //
tuple(InsertRoot.class, RootWithEmbeddedReferenceChainEntity.class, "", RootWithEmbeddedReferenceChainEntity.class, false), //
tuple(Insert.class, EmbeddedReferenceChainEntity.class, "other", EmbeddedReferenceChainEntity.class, true) //
);
}

private CascadingReferenceMiddleElement createMiddleElement(Element first, Element second) {

CascadingReferenceMiddleElement middleElement1 = new CascadingReferenceMiddleElement(null);
Expand Down Expand Up @@ -560,13 +605,6 @@ private Object getQualifier(DbAction a, PersistentPropertyPath<RelationalPersist
: null;
}

private int getQualifierCount(DbAction a, PersistentPropertyPath<RelationalPersistentProperty> path) {

return a instanceof DbAction.WithDependingOn //
? ((DbAction.WithDependingOn) a).getQualifiers().size() //
: 0;
}

static PersistentPropertyPath<RelationalPersistentProperty> toPath(String path, Class source,
RelationalMappingContext context) {

Expand All @@ -592,6 +630,19 @@ static class EmbeddedReferenceEntity {
@Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "prefix_") Element other;
}

@RequiredArgsConstructor
static class EmbeddedReferenceChainEntity {

@Id final Long id;
@Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "prefix_") ElementReference other;
}
@RequiredArgsConstructor
static class RootWithEmbeddedReferenceChainEntity {

@Id final Long id;
EmbeddedReferenceChainEntity other;
}

@RequiredArgsConstructor
static class ReferenceWoIdEntity {

Expand Down Expand Up @@ -648,6 +699,11 @@ private static class Element {
@Id final Long id;
}

@RequiredArgsConstructor
private static class ElementReference {
final Element element;
}

@RequiredArgsConstructor
private static class NoIdListMapContainer {

Expand Down