Here is my table structure. I am using spring-boot-starter-data-jdbc
3.0.3. I mapped these tables like below.
@Table("ticket")
public class Ticket {
@Id
private int id;
private String subject;
private TicketType ticketType;
// getters and setters
}
@Table("ticket_type")
public class TicketType {
@Id
private int id;
private String name;
// getters and setters
}
when I try to retrieve tickets, spring throws a BadSqlGrammarException. The generated query is
SELECT `ticket`.`id` AS `id`, `ticket`.`subject` AS `subject`, `ticketType`.`id` AS `tickettype_id`, `ticketType`.`name` AS `tickettype_name` FROM `ticket` LEFT OUTER JOIN `ticket_type` `ticketType` ON `ticketType`.`ticket` = `ticket`.`id`
why spring data JDBC generates the on cause as
`ticketType`.`ticket` = `ticket`.`id`
instead of
`ticketType`.`id` = `ticket`.`ticket_type`
I tried @MappedCollection(idColumn = "ticket_id") to the ticketType field in Ticket class. then the on cause of generated query was ticketType
.ticket_id
= ticket
.id
. what am I doing wrong ?