Skip to content

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

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

Closed
spring-projects-issues opened this issue Oct 12, 2018 · 1 comment
Assignees
Labels
in: core Issues in core support type: bug A general bug

Comments

@spring-projects-issues
Copy link

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

@spring-projects-issues
Copy link
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

@spring-projects-issues spring-projects-issues added type: bug A general bug in: core Issues in core support labels Dec 31, 2020
@spring-projects-issues spring-projects-issues added this to the 1.1 M1 (Moore) milestone Dec 31, 2020
schauder added a commit that referenced this issue Jan 31, 2022
schauder added a commit that referenced this issue Feb 15, 2022
mp911de pushed a commit that referenced this issue Feb 21, 2022
mp911de added a commit that referenced this issue Feb 21, 2022
Reorder methods. Replace Guava imports with proper ones. Consistent override comments.

Original pull request: #501.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core support type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants