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

JdbcCustomConversions not applied to primary key on lookup [DATAJDBC-349] #571

Closed
spring-projects-issues opened this issue Apr 1, 2019 · 2 comments
Assignees
Labels

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Apr 1, 2019

Dav1dde opened DATAJDBC-349 and commented

Code:

public class StockImageEntity implements AggregateRoot {
    @Id
    @Column("ID")
    private UUID id;

    @Singular
    @Column("IMAGE_ID")
    private Set<ImageResolutionEntity> resolutions;
}

public class ImageResolutionEntity implements Identifiable {
    @Id
    @Column("ID")
    private UUID id;
} 

 

@Configuration
public class CustomJdbcConfiguration extends JdbcConfiguration {
    @Override
    public RelationalMappingContext jdbcMappingContext(Optional<NamingStrategy> namingStrategy) {
        return super.jdbcMappingContext(namingStrategy);
    }    @Override
    public RelationalConverter relationalConverter(RelationalMappingContext mappingContext) {
        return super.relationalConverter(mappingContext);
    }    @Override
    public JdbcCustomConversions jdbcCustomConversions() {
        return new JdbcCustomConversions(List.of(
            MediaTypeStringConverters.reader(),
            MediaTypeStringConverters.writer(),
            UuidStringConverters.reader(),
            UuidStringConverters.writer()
        ));
    }
}

Now querying for a StockImageEntity results in the following exception:

Caused by: java.sql.SQLException: Invalid column typeCaused by: java.sql.SQLException: Invalid column type at oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:8488) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0] at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7995) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0] at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:8735) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0] at oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:8714) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0] at oracle.jdbc.driver.OraclePreparedStatementWrapper.setObject(OraclePreparedStatementWrapper.java:219) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0] at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.setObject(HikariProxyPreparedStatement.java) ~[HikariCP-3.2.0.jar:na] at org.springframework.jdbc.core.StatementCreatorUtils.setValue(StatementCreatorUtils.java:411) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:232) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:147) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.setValues(PreparedStatementCreatorFactory.java:286) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.createPreparedStatement(PreparedStatementCreatorFactory.java:244) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:615) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE] ... 80 common frames omitted

 

The Problem seems to be in org.springframework.data.jdbc.core.DefaultDataAccessStrategy#findAllByProperty:

MapSqlParameterSource parameter = new MapSqlParameterSource(property.getReverseColumnName(), rootId);

Where rootId is the unconverted UUID. This might also be a problem for delete Operations


Attachments:

Issue Links:

  • DATAJDBC-587 Convert identity value object to SQL type with custom converter in Finding and Deletion by property path
    ("is duplicated by")

2 votes, 4 watchers

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jun 6, 2020

zustse commented

I can confirm this bug and it makes it impossible to connect two entities which have a uuid as primary key with a many-to-many relation. In my attached example I have two entities Person with table name person and Resource with table name resource that are connected via a ResourceRef with table name person_resource. When you take a look into this log excerpt which is produced by the test in the attached example

2020-06-06 17:55:56.260 DEBUG 47063 --- [    Test worker] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [DELETE FROM `person_resource` WHERE `person_resource`.`person` = ?]
2020-06-06 17:55:56.260 TRACE 47063 --- [    Test worker] o.s.jdbc.core.StatementCreatorUtils      : Setting SQL statement parameter value: column index 1, parameter value [185d0f4d-d7e7-4810-ad31-f69124fe424f], value class [java.util.UUID], SQL type unknown
2020-06-06 17:55:56.267 DEBUG 47063 --- [    Test worker] o.s.jdbc.core.JdbcTemplate               : Executing SQL update and returning generated keys
2020-06-06 17:55:56.267 DEBUG 47063 --- [    Test worker] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [INSERT INTO `person_resource` (`person`, `resource`) VALUES (?, ?)]
2020-06-06 17:55:56.268 TRACE 47063 --- [    Test worker] o.s.jdbc.core.StatementCreatorUtils      : Setting SQL statement parameter value: column index 1, parameter value [[B@3c6629c6], value class [[B], SQL type -2
2020-06-06 17:55:56.268 TRACE 47063 --- [    Test worker] o.s.jdbc.core.StatementCreatorUtils      : Setting SQL statement parameter value: column index 2, parameter value [[B@14d3170d], value class [[B], SQL type -2

you can see that the uuid isn't converted into binary form in the WHERE clause of the DELETE statement

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Sep 12, 2020

lseeker commented

I found id property not using jdbc type converter when resolves relation.
Here is PR: #248

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants