Skip to content

Creating entity via constructor assumes child properties are nested entities [DATAJDBC-273] #498

Closed
@spring-projects-issues

Description

@spring-projects-issues

Andrew Thorburn opened DATAJDBC-273 and commented

Given an entity definition like (in Kotlin), full code at the reference URL:

data class Application(
  @Id
  val applicationId: Int,
  val applicationState: String,
  @Column(value = "APPLICATION_ID", keyColumn = "APPLICANT_ORDER")
  var applicants: List<Applicant>
)

data class Applicant(...)

Attempting to load that entity gives the following partial exception:

2018-10-12 14:51:58.314 ERROR 58488 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.mapping.MappingException: Could not read value applicants_APPLICATION_ID from result set!] with root cause

org.hsqldb.HsqlException: Column not found: applicants_applicant_id
    at org.hsqldb.error.Error.error(Unknown Source) ~[hsqldb-2.4.1.jar:2.4.1]
    at org.hsqldb.error.Error.error(Unknown Source) ~[hsqldb-2.4.1.jar:2.4.1]
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) ~[hsqldb-2.4.1.jar:2.4.1]
    at org.hsqldb.jdbc.JDBCResultSet.findColumn(Unknown Source) ~[hsqldb-2.4.1.jar:2.4.1]
    at org.hsqldb.jdbc.JDBCResultSet.getObject(Unknown Source) ~[hsqldb-2.4.1.jar:2.4.1]
    at org.springframework.data.jdbc.core.EntityRowMapper.getObjectFromResultSet(EntityRowMapper.java:164) ~[spring-data-jdbc-1.1.0.DATAJDBC-271-SNAPSHOT.jar:1.1.0.DATAJDBC-271-SNAPSHOT]
    at org.springframework.data.jdbc.core.EntityRowMapper.readFrom(EntityRowMapper.java:126) ~[spring-data-jdbc-1.1.0.DATAJDBC-271-SNAPSHOT.jar:1.1.0.DATAJDBC-271-SNAPSHOT]
    at org.springframework.data.jdbc.core.EntityRowMapper.readEntityFrom(EntityRowMapper.java:143) ~[spring-data-jdbc-1.1.0.DATAJDBC-271-SNAPSHOT.jar:1.1.0.DATAJDBC-271-SNAPSHOT]
    at org.springframework.data.jdbc.core.EntityRowMapper.readFrom(EntityRowMapper.java:123) ~[spring-data-jdbc-1.1.0.DATAJDBC-271-SNAPSHOT.jar:1.1.0.DATAJDBC-271-SNAPSHOT]
    at org.springframework.data.jdbc.core.EntityRowMapper.lambda$createInstance$0(EntityRowMapper.java:179) ~[spring-data-jdbc-1.1.0.DATAJDBC-271-SNAPSHOT.jar:1.1.0.DATAJDBC-271-SNAPSHOT]

Per Mark Paluch, the cause is this:

It’s a bug in Spring Data JDBC related to constructor creation

So all the poking around the embedded @Id wasn’t really the cause

For Kotlin data classes, we attempt to create the entity using its constructor and in that code path we have a bug that assumes the applicant is a nested entity.


Affects: 1.0 GA (Lovelace)

Reference URL: https://github.com/ipsi/spring-data-jdbc-playground

Referenced from: pull request #96, and commits aec5722, 9fb5aad, baeb8d8

1 votes, 2 watchers

Activity

spring-projects-issues

spring-projects-issues commented on Oct 19, 2018

@spring-projects-issues
Author

Maciej Walkowiak commented

It would be really great to get the fix merged in next release, as it's now impossible to use immutable objects with one-to-many relations

added a commit that references this issue on Jan 31, 2022
added a commit that references this issue on Feb 15, 2022
added 2 commits that reference this issue on Feb 21, 2022

#498 - Implements ReactiveCrudRepository.deleteAllById.

843c402

#498 - Polishing.

cf75e26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coreIssues in core supporttype: bugA general bug

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @schauder@spring-projects-issues

      Issue actions

        Creating entity via constructor assumes child properties are nested entities [DATAJDBC-273] · Issue #498 · spring-projects/spring-data-relational