Skip to content

Synthetic constructors should not be considered persistence constructors [DATACMNS-1082] #1526

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 Jun 7, 2017 · 0 comments
Assignees
Labels
in: core Issues in core support type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link

Roman Rodov opened DATACMNS-1082 and commented

As the title says Synthetic Constructors Should not be considered by org.springframework.data.mapping.model.PreferredConstructorDiscoverer as it is also common for them not to have correct parameter names to map to fields.

Exmaple, in Kotlin combined with Spring Data Mongo

The following class (just a dumbed down example):

@Document
data class Address @PersistenceConstructor constructor(
    val postcode: String,
    val state: String,
    var streetAddress: StreetAddress? = null
)

Will cause Kotlin to generate 2 constructors (because of the use of "default" parameter:

@PersistenceConstructor public Address(String postcode,String state,StreetAddress streetAddress) { ... }

and

@PersistenceConstructor public /* synthetic */ Address(String arg0, String arg1, StreetAddress arg2, int arg3, DefaultConstructorMarker arg4) { ... }

PreferredConstructorDiscoverer in random order (sometimes it will, sometimes it won't, due to order of the constructors in bytecode) will pick the synthetic constructor which will cause a MappingException with message: No property null found on entity Address to bind constructor parameter to! Notice the null value. That is because the synthetic constructor does not have parameter meta data.

I have a PR ready, which is super simple I guess


Affects: 2.0 M3 (Kay), 1.13.3 (Ingalls SR3)

Referenced from: pull request #225

Backported to: 1.13.4 (Ingalls SR4), 1.12.11 (Hopper SR11)

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