Closed
Description
spring-data-jdbc 2.3.0
@Data
public class User {
@Id
private Long id;
private Date createdTime;
private Date updatedTime;
@Column("DOB")
private Date dateofBirth;
@MappedCollection(idColumn = "CREDS_ID")
private Credentials credentials;
}
@Table("USER_CREDENTIALS")
@Data // lombok
public class Credentials {
@Id
private Long credsId;
private String userName;
private String password;
}
public interface UserRepository extends PagingAndSortingRepository<User, Integer> {
}
//test
Optional<User> user = userRepository.findById(1);
expect sql:
SELECT `user`.`id` AS `id`, `user`.`DOB` AS `DOB`, `user`.`created_time` AS `created_time`, `user`.`updated_time` AS `updated_time`, `credentials`.`creds_id` AS `credentials_creds_id`, `credentials`.`password` AS `credentials_password`, `credentials`.`user_name` AS `credentials_user_name` FROM `user` LEFT OUTER JOIN `USER_CREDENTIALS` `credentials` ON `credentials`.`CREDS_ID` = `user`.`CREDS_ID` WHERE `user`.`id` = :id
actual sql:
SELECT `user`.`id` AS `id`, `user`.`DOB` AS `DOB`, `user`.`created_time` AS `created_time`, `user`.`updated_time` AS `updated_time`, `credentials`.`creds_id` AS `credentials_creds_id`, `credentials`.`password` AS `credentials_password`, `credentials`.`user_name` AS `credentials_user_name` FROM `user` LEFT OUTER JOIN `USER_CREDENTIALS` `credentials` ON `credentials`.`CREDS_ID` = `user`.`id` WHERE `user`.`CREDS_ID` = :id