Open NielsCW opened 6 days ago
I did some reproducing, debugging and testing here: https://github.com/spring-projects/spring-data-relational/pull/1829 That draft PR also explains what the problem is. This will need some input from the rest of the team.
Given following example with 2 entities: project and user, each having a custom datatype as id. User has a reference to project using
AggregatedReference<ProjectEntity, ProjectId>
. When Upgrading Spring Boot from 3.2.5 to 3.3.1, the application fails to create a user because theAggregatedReference
is not resolved to a simple type (creating a project works).During debugging I see that in Spring Boot 3.3.1
AggregatedReference<ProjectEntity, ProjectId>
is only converted to aProjectId
while in Spring Boot 3.2.5 the resultingProjectId
is further converted toUUID
byMappingRelationalConverter::getPotentiallyConvertedSimpleWrite
CREATE TABLE user ( id UUID NOT NULL PRIMARY KEY, name varchar NOT NULL, project_id UUID NOT NULL REFERENCES project(id) );
Custom Id (
UserId
is identical):Converters (those for
UserId
are identical):@ReadingConverter public class UUIDToProjectIdConverter implements Converter<UUID, ProjectId> {
}
org.springframework.data.relational.core.conversion.DbActionExecutionException: Failed to execute InsertRoot{entity=com.example.demo.model.UserEntity@1b06dc57, idValueSource=PROVIDED}
Caused by: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [INSERT INTO "user" ("id", "name", "project_id") VALUES (?, ?, ?)] at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:112) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:107) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:116) at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1548) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:677) at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:970) at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:991) at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.update(NamedParameterJdbcTemplate.java:337) at org.springframework.data.jdbc.core.convert.InsertStrategyFactory$DefaultInsertStrategy.execute(InsertStrategyFactory.java:96) at org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy.insert(DefaultDataAccessStrategy.java:110) at org.springframework.data.jdbc.core.JdbcAggregateChangeExecutionContext.executeInsertRoot(JdbcAggregateChangeExecutionContext.java:83) at org.springframework.data.jdbc.core.AggregateChangeExecutor.execute(AggregateChangeExecutor.java:85) ... 35 more Caused by: org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of com.example.demo.model.ProjectId. Use setObject() with an explicit Types value to specify the type to use. at org.postgresql.jdbc.PgPreparedStatement.setObject(PgPreparedStatement.java:1076) at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.setObject(HikariProxyPreparedStatement.java) at org.springframework.jdbc.core.StatementCreatorUtils.setValue(StatementCreatorUtils.java:453) at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:247) at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:163) at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.setValues(PreparedStatementCreatorFactory.java:287) at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.createPreparedStatement(PreparedStatementCreatorFactory.java:245) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:656) ... 42 more