-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Open
Labels
in: dataIssues in data modules (jdbc, orm, oxm, tx)Issues in data modules (jdbc, orm, oxm, tx)status: waiting-for-triageAn issue we've not yet triaged or decided onAn issue we've not yet triaged or decided on
Description
When I have a class with multiple constructors:
class Person {
private int id;
private String name;
Person(int id, String name) {
this.id = id;
this.name = name;
}
Person(String name) {
this(0, name);
}
}I can't use it as a parameter of the method query of JdbcClient:
jdbcClient.sql("select id,name from persons").query(Person.class).list();It causes an exception:
java.lang.IllegalStateException: No primary or single unique constructor found
This is a pity: when i make a new Person somewhere in my code, i can't type:
new Person("John");but I must type (id is an autonumber in the database):
new Person(0, "John"); // a surrogate value for idIs it possible to relax this one-constructor restriction a bit?
- If
JdbcClientdetects multiple constructors, it counts the number of columns in theResultSetof the query. - If there is only one constructor with the same number of parameters as this number of columns, it uses that constructor.
quaff
Metadata
Metadata
Assignees
Labels
in: dataIssues in data modules (jdbc, orm, oxm, tx)Issues in data modules (jdbc, orm, oxm, tx)status: waiting-for-triageAn issue we've not yet triaged or decided onAn issue we've not yet triaged or decided on