Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix access of root property instead of child property #1775

Closed
wants to merge 2 commits into from
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>3.3.0-SNAPSHOT</version>
<version>3.3.0-1684-converter-not-found-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>3.3.0-SNAPSHOT</version>
<version>3.3.0-1684-converter-not-found-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 @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-jdbc</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.3.0-1684-converter-not-found-SNAPSHOT</version>

<name>Spring Data JDBC</name>
<description>Spring Data module for JDBC repositories.</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.3.0-1684-converter-not-found-SNAPSHOT</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ private ResolvingRelationalPropertyValueProvider(AggregatePathValueProvider dele
this.accessor = accessor;
this.context = context;
this.identifier = path.isEntity()
? potentiallyAppendIdentifier(identifier, path.getRequiredLeafEntity(), delegate::getPropertyValue)
? potentiallyAppendIdentifier(identifier, path.getRequiredLeafEntity(), property -> delegate.getValue(path.append(property)))
: identifier;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,16 @@ void mapWithEnumKey() {
assertThat(enumMapOwners).containsExactly(enumMapOwner);
}

@Test // GH-1684
void oneToOneWithIdenticalIdColumnName(){

WithOneToOne saved = template.insert(new WithOneToOne("one", new Referenced(23L)));

WithOneToOne reloaded = template.findById(saved.id, WithOneToOne.class);

assertThat(reloaded).isEqualTo(saved);
}

private <T extends Number> void saveAndUpdateAggregateWithVersion(VersionedAggregate aggregate,
Function<Number, T> toConcreteNumber) {
saveAndUpdateAggregateWithVersion(aggregate, toConcreteNumber, 0);
Expand Down Expand Up @@ -2086,6 +2096,10 @@ record Book(String name) {
record EnumMapOwner(@Id Long id, String name, Map<Color, MapElement> map) {
}

record WithOneToOne(@Id String id,@MappedCollection(idColumn = "renamed") Referenced referenced){}

record Referenced(@Id Long id) {
}

@Configuration
@Import(TestConfiguration.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.assertj.core.api.SoftAssertions;
Expand All @@ -39,8 +40,10 @@
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.jdbc.core.mapping.JdbcValue;
import org.springframework.data.jdbc.support.JdbcUtil;
import org.springframework.data.relational.core.mapping.MappedCollection;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.domain.RowDocument;
import org.springframework.data.util.TypeInformation;

/**
Expand Down Expand Up @@ -139,6 +142,17 @@ void conversionOfPrimitiveArrays() {
assertThat(typeFactory.arraySource).containsExactly(1, 2, 3, 4, 5);
}

@Test // GH-1684
void accessesCorrectValuesForOneToOneRelationshipWithIdenticallyNamedIdProperties() {

RowDocument rowdocument = new RowDocument(Map.of("ID", "one", "REFERENCED_ID", 23));

WithOneToOne result = converter.readAndResolve(WithOneToOne.class, rowdocument);

assertThat(result).isEqualTo(new WithOneToOne("one", new Referenced(23L)));
}


private void checkConversionToTimestampAndBack(SoftAssertions softly, RelationalPersistentEntity<?> persistentEntity,
String propertyName, Object value) {

Expand Down Expand Up @@ -284,4 +298,10 @@ public Array createArray(Object[] value) {
return mock(Array.class);
}
}

record WithOneToOne(@Id String id,@MappedCollection(idColumn = "renamed") Referenced referenced){}

record Referenced(@Id Long id) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ DROP TABLE AUTHOR;

DROP TABLE ENUM_MAP_OWNER;

DROP TABLE REFERENCED;
DROP TABLE WITH_ONE_TO_ONE;


CREATE TABLE LEGO_SET
(
"id1" BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY,
Expand Down Expand Up @@ -428,4 +432,15 @@ CREATE TABLE ENUM_MAP_OWNER
(
ID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY,
NAME VARCHAR(100)
);
);

CREATE TABLE WITH_ONE_TO_ONE
(
ID VARCHAR(100)
);

CREATE TABLE REFERENCED
(
"renamed" VARCHAR(100),
ID BIGINT
);
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,15 @@ CREATE TABLE ENUM_MAP_OWNER
(
ID SERIAL PRIMARY KEY,
NAME VARCHAR(100)
);
);

CREATE TABLE WITH_ONE_TO_ONE
(
ID VARCHAR(100)
);

CREATE TABLE REFERENCED
(
"renamed" VARCHAR(100),
ID BIGINT
);
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,15 @@ CREATE TABLE ENUM_MAP_OWNER
ID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY,
NAME VARCHAR(100)
);


CREATE TABLE WITH_ONE_TO_ONE
(
ID VARCHAR(100)
);

CREATE TABLE REFERENCED
(
"renamed" VARCHAR(100),
ID BIGINT
);
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,15 @@ CREATE TABLE ENUM_MAP_OWNER
(
ID BIGINT AUTO_INCREMENT PRIMARY KEY,
NAME VARCHAR(100)
);
);

CREATE TABLE WITH_ONE_TO_ONE
(
ID VARCHAR(100)
);

CREATE TABLE REFERENCED
(
`renamed` VARCHAR(100),
ID BIGINT
);
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,19 @@ CREATE TABLE ENUM_MAP_OWNER
(
ID BIGINT IDENTITY PRIMARY KEY,
NAME VARCHAR(100)
);
);


DROP TABLE REFERENCED;
DROP TABLE WITH_ONE_TO_ONE;

CREATE TABLE WITH_ONE_TO_ONE
(
ID VARCHAR(100)
);

CREATE TABLE REFERENCED
(
"renamed" VARCHAR(100),
ID BIGINT
);
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,16 @@ CREATE TABLE ENUM_MAP_OWNER
(
ID BIGINT AUTO_INCREMENT PRIMARY KEY,
NAME VARCHAR(100)
);
);


CREATE TABLE WITH_ONE_TO_ONE
(
ID VARCHAR(100)
);

CREATE TABLE REFERENCED
(
`renamed` VARCHAR(100),
ID BIGINT
);
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ DROP TABLE AUTHOR CASCADE CONSTRAINTS PURGE;

DROP TABLE ENUM_MAP_OWNER CASCADE CONSTRAINTS PURGE;

DROP TABLE REFERENCED CASCADE CONSTRAINTS PURGE;
DROP TABLE WITH_ONE_TO_ONE CASCADE CONSTRAINTS PURGE;

CREATE TABLE LEGO_SET
(
"id1" NUMBER GENERATED by default on null as IDENTITY PRIMARY KEY,
Expand Down Expand Up @@ -409,4 +412,15 @@ CREATE TABLE ENUM_MAP_OWNER
(
ID NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
NAME VARCHAR(100)
);
);

CREATE TABLE WITH_ONE_TO_ONE
(
ID VARCHAR(100)
);

CREATE TABLE REFERENCED
(
"renamed" VARCHAR(100),
ID NUMBER
);
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ DROP TABLE AUTHOR;

DROP TABLE ENUM_MAP_OWNER;

DROP TABLE REFERENCED;
DROP TABLE WITH_ONE_TO_ONE;

CREATE TABLE LEGO_SET
(
"id1" SERIAL PRIMARY KEY,
Expand Down Expand Up @@ -431,4 +434,15 @@ CREATE TABLE ENUM_MAP_OWNER
(
ID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY,
NAME VARCHAR(100)
);
);

CREATE TABLE WITH_ONE_TO_ONE
(
ID VARCHAR(100)
);

CREATE TABLE REFERENCED
(
"renamed" VARCHAR(100),
ID BIGINT
);
4 changes: 2 additions & 2 deletions spring-data-r2dbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-r2dbc</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.3.0-1684-converter-not-found-SNAPSHOT</version>

<name>Spring Data R2DBC</name>
<description>Spring Data module for R2DBC</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.3.0-1684-converter-not-found-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 @@ -6,15 +6,15 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-relational</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.3.0-1684-converter-not-found-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>3.3.0-SNAPSHOT</version>
<version>3.3.0-1684-converter-not-found-SNAPSHOT</version>
</parent>

<properties>
Expand Down
Loading