Answer the question
In order to leave comments, you need to log in
How to make a selection in CrudController by JoinColumn without using join?
Hello.
There is a Comment class that has a user field defined like this:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
@NonNull
private User user;
public interface CommentRepository extends CrudRepository<Comment, Integer> {
List<Comment> findByUserId(Integer userId);
}
commentRepository.findByUserId(user.getId());
select
comment0_."id" as id1_1_,
comment0_."text" as url2_1_,
comment0_."user_id" as user_id3_1_
from
"comments" comment0_
left outer join
"users" user1_
on comment0_."user_id"=user1_."id"
where
user1_."id"=?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question