diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java index 8b1e729f7..4a98475ae 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java @@ -66,6 +66,7 @@ import org.springframework.util.Assert; * @author Tyler Van Gorder * @author Milan Milanov * @author Myeonghyeon Lee + * @author Yunyoung LEE * @since 1.1 */ public class DefaultDataAccessStrategy implements DataAccessStrategy { @@ -227,7 +228,12 @@ public class DefaultDataAccessStrategy implements DataAccessStrategy { String delete = sql(rootEntity.getType()).createDeleteByPath(propertyPath); SqlIdentifierParameterSource parameters = new SqlIdentifierParameterSource(getIdentifierProcessing()); - parameters.addValue(ROOT_ID_PARAMETER, rootId); + addConvertedPropertyValue( // + parameters, // + rootEntity.getRequiredIdProperty(), // + rootId, // + ROOT_ID_PARAMETER // + ); operations.update(delete, parameters); } @@ -367,7 +373,8 @@ public class DefaultDataAccessStrategy implements DataAccessStrategy { SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(identifierProcessing); - identifier.toMap().forEach(parameterSource::addValue); + identifier.toMap() + .forEach((name, value) -> addConvertedPropertyValue(parameterSource, name, value, value.getClass())); return parameterSource; } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryPropertyConversionIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryPropertyConversionIntegrationTests.java index 8b44205d7..8b7c3e295 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryPropertyConversionIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryPropertyConversionIntegrationTests.java @@ -29,12 +29,12 @@ import java.time.LocalDateTime; import java.time.ZoneOffset; import java.util.Collections; import java.util.Date; +import java.util.Set; import org.assertj.core.api.Condition; import org.assertj.core.api.SoftAssertions; import org.junit.Test; import org.junit.runner.RunWith; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationListener; import org.springframework.context.annotation.Bean; @@ -45,6 +45,7 @@ import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory; import org.springframework.data.jdbc.testing.AssumeFeatureRule; import org.springframework.data.jdbc.testing.EnabledOnFeature; import org.springframework.data.jdbc.testing.TestConfiguration; +import org.springframework.data.relational.core.mapping.MappedCollection; import org.springframework.data.relational.core.mapping.event.BeforeSaveEvent; import org.springframework.data.repository.CrudRepository; import org.springframework.test.context.ContextConfiguration; @@ -58,6 +59,7 @@ import org.springframework.transaction.annotation.Transactional; * * @author Jens Schauder * @author Thomas Lang + * @author Yunyung LEE */ @ContextConfiguration @Transactional @@ -77,6 +79,9 @@ public class JdbcRepositoryPropertyConversionIntegrationTests { entity.setBigInteger(BigInteger.valueOf(Long.MAX_VALUE)); entity.setDate(Date.from(getNow().toInstant(ZoneOffset.UTC))); entity.setLocalDateTime(getNow()); + EntityWithColumnsRequiringConversionsRelation relation = new EntityWithColumnsRequiringConversionsRelation(); + relation.setData("DUMMY"); + entity.setRelation(singleton(relation)); return entity; } @@ -194,5 +199,13 @@ public class JdbcRepositoryPropertyConversionIntegrationTests { // ensures conversion on id querying @Id private LocalDateTime idTimestamp; + @MappedCollection(idColumn = "ID_TIMESTAMP") Set relation; + } + + // DATAJDBC-349 + @Data + static class EntityWithColumnsRequiringConversionsRelation { + @Id private LocalDateTime idTimestamp; + String data; } } diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-db2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-db2.sql index dba16a76d..bfc3eda31 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-db2.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-db2.sql @@ -1,3 +1,4 @@ +DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION; DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS; CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( @@ -10,3 +11,8 @@ CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( local_Date_Time DATETIME, zoned_Date_Time VARCHAR(30) ); + +CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION ( + id_Timestamp DATETIME NOT NULL PRIMARY KEY, + data VARCHAR(100), +); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-h2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-h2.sql index 8fe6fbee7..3eb1994c2 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-h2.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-h2.sql @@ -1 +1,2 @@ -CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( id_Timestamp DATETIME PRIMARY KEY, bool boolean, SOME_ENUM VARCHAR(100), big_Decimal DECIMAL(1025), big_Integer DECIMAL(20), date DATETIME, local_Date_Time DATETIME, zoned_Date_Time VARCHAR(30)) +CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( id_Timestamp DATETIME PRIMARY KEY, bool boolean, SOME_ENUM VARCHAR(100), big_Decimal DECIMAL(1025), big_Integer DECIMAL(20), date DATETIME, local_Date_Time DATETIME, zoned_Date_Time VARCHAR(30)); +CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION ( id_Timestamp DATETIME NOT NULL PRIMARY KEY, data VARCHAR(100)); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-hsql.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-hsql.sql index 8fe6fbee7..3eb1994c2 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-hsql.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-hsql.sql @@ -1 +1,2 @@ -CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( id_Timestamp DATETIME PRIMARY KEY, bool boolean, SOME_ENUM VARCHAR(100), big_Decimal DECIMAL(1025), big_Integer DECIMAL(20), date DATETIME, local_Date_Time DATETIME, zoned_Date_Time VARCHAR(30)) +CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( id_Timestamp DATETIME PRIMARY KEY, bool boolean, SOME_ENUM VARCHAR(100), big_Decimal DECIMAL(1025), big_Integer DECIMAL(20), date DATETIME, local_Date_Time DATETIME, zoned_Date_Time VARCHAR(30)); +CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION ( id_Timestamp DATETIME NOT NULL PRIMARY KEY, data VARCHAR(100)); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mariadb.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mariadb.sql index 3f08147dd..8e100e80a 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mariadb.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mariadb.sql @@ -1 +1,2 @@ -CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( id_Timestamp DATETIME PRIMARY KEY, bool boolean, SOME_ENUM VARCHAR(100), big_Decimal DECIMAL(65), big_Integer DECIMAL(20), date DATETIME, local_Date_Time DATETIME, zoned_Date_Time VARCHAR(30)) +CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( id_Timestamp DATETIME PRIMARY KEY, bool boolean, SOME_ENUM VARCHAR(100), big_Decimal DECIMAL(65), big_Integer DECIMAL(20), date DATETIME, local_Date_Time DATETIME, zoned_Date_Time VARCHAR(30)); +CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION ( id_Timestamp DATETIME NOT NULL PRIMARY KEY, data VARCHAR(100)); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mssql.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mssql.sql index 0a420bdf9..b4fc5fde2 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mssql.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mssql.sql @@ -1,2 +1,4 @@ +DROP TABLE IF EXISTS ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION; DROP TABLE IF EXISTS ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS; CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( id_Timestamp DATETIME PRIMARY KEY, bool bit, SOME_ENUM VARCHAR(100), big_Decimal DECIMAL(38), big_Integer DECIMAL(20), date DATETIME, local_Date_Time DATETIME, zoned_Date_Time VARCHAR(30)); +CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION ( id_Timestamp DATETIME NOT NULL PRIMARY KEY, data VARCHAR(100)); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mysql.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mysql.sql index 3f08147dd..8e100e80a 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mysql.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mysql.sql @@ -1 +1,2 @@ -CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( id_Timestamp DATETIME PRIMARY KEY, bool boolean, SOME_ENUM VARCHAR(100), big_Decimal DECIMAL(65), big_Integer DECIMAL(20), date DATETIME, local_Date_Time DATETIME, zoned_Date_Time VARCHAR(30)) +CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( id_Timestamp DATETIME PRIMARY KEY, bool boolean, SOME_ENUM VARCHAR(100), big_Decimal DECIMAL(65), big_Integer DECIMAL(20), date DATETIME, local_Date_Time DATETIME, zoned_Date_Time VARCHAR(30)); +CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION ( id_Timestamp DATETIME NOT NULL PRIMARY KEY, data VARCHAR(100)); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-oracle.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-oracle.sql index bfa63a532..0023a053a 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-oracle.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-oracle.sql @@ -1,3 +1,4 @@ +DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION; DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS; CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( @@ -10,3 +11,8 @@ CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( LOCAL_DATE_TIME TIMESTAMP, ZONED_DATE_TIME VARCHAR2(30) ); + +CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION ( + ID_TIMESTAMP TIMESTAMP PRIMARY KEY, + DATA VARCHAR2(100), +); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-postgres.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-postgres.sql index c55f4c320..0186c5bf9 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-postgres.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-postgres.sql @@ -1,2 +1,4 @@ +DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION; DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS; CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( id_Timestamp TIMESTAMP PRIMARY KEY, bool boolean, SOME_ENUM VARCHAR(100), big_Decimal DECIMAL(65), big_Integer BIGINT, date TIMESTAMP, local_Date_Time TIMESTAMP, zoned_Date_Time VARCHAR(30)) +CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS_RELATION ( id_Timestamp DATETIME NOT NULL PRIMARY KEY, data VARCHAR(100));