Skip to content

MappedCollection One to One bug  #1123

Closed
@githubyong

Description

@githubyong

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions