I have SQL schema and Java class for issue and ticket model defined as follow:
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Ticket {
private long id;
private int ticket_int_1;
private int ticket_int_2;
private int ticket_int_3;
private String ticket_varchar_1;
private String dateFiled;
private String dateLastUpdated;
private String dateResolved;
}
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@ToString
public class Issue {
private long id;
private long issue_bigInt_1;
private long issue_bigInt_2;
private int issue_int_1;
@EqualsAndHashCode.Include
private long issue_bigInt_3;
private int issue_int_2;
@EqualsAndHashCode.Include
private int issue_int_3;
@EqualsAndHashCode.Include
private String issue_varchar_1;
@EqualsAndHashCode.Include
private String issue_varchar_2;
@EqualsAndHashCode.Include
private String issue_varchar_3;
private int issue_int_4;
private String dateResolved;
private String dateCreated;
private String dateUpdate;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class TicketIssue {
private long id;
private int ticket_issue_int_1;
private long issueId; // issue will be the many
private long ticketId; // ticket will be the 1
}
According to the official doc, I wrote the following code:
String selectSql = "SELECT t.*, i.* FROM " + ISSUE_TABLE + " as i"
+ " JOIN " + TICKET_ISSUES_TABLE + " as ti on i.id = ti.issue_id"
+ " JOIN " + TICKET_TABLE + " as t on ti.ticket_id = t.id";
jdbi.useHandle(handle ->
handle.registerRowMapper(BeanMapper.factory(Ticket.class, "t"))
.registerRowMapper(BeanMapper.factory(Issue.class, "i"))
.registerRowMapper(JoinRowMapper.forTypes(Ticket.class, Issue.class))
.createQuery(selectSql)
.mapTo(JoinRow.class));
Executing above query throws an error:
java.lang.IllegalArgumentException: Mapping bean class Ticket didn't find any matching columns in result set
My implementation looks exactly the same with the documentation, what went wrong here? Can anyone help?
The issue is the prefix looks for "prefix_" instead of "prefix." So I will have to explicitly add the alias for the select query to work: