I have two tables user and student. Student and user has one to one relationship. I am mapping same column with both userId and UserEntity inside StudentEntity
@Entity @Table(name = "user") public class User { @Id private UUID id; @Column(name = "name") private String name; ... // getter setter ignored for brevity }
@Entity @Table(name = "student") public class Student { @Id private UUID id; @Column(name = "user_id") private UUID userId; @OneToOne @JoinColumn(name = "user_id", referencedColumnName = "id", insertable = false, updatable = false) private UserEntity userEntity; ... // getter setter ignored for brevity }
@Repository
public interface StudentRepository extend PagingAndSortingRepository<StudentEntity, UUID> {
Optional<StudentEntity> findByUserId(UUID userId);
}
Now when I call any of below method UserEntity is not populated
StudentEntity student = studentRepository.findByUserId(userId).get() student.getUserId() --- this is present student.getUserEntity() -- NULL
Not sure why UserEntity is not getting populated as a part of this call.