인프런 커뮤니티 질문&답변
추가로 Repository 작성할 때 궁금한 점이 있어서 여쭤봅니다.
작성
·
253
0
만약 consumer와 post라는 테이블이 있을 때
post에 consumer_id가 @ManyToOne 관계로 FK일 때 해당 consumer 객체의 post 갯수를 알고 싶을 때 이렇게 사용할 수도 있는 건가요?
public List<String> findAllWith() {
return em.createQuery("select c.id, c.cId, count(p.id) as post_num from Consumer c, Post p where c.id = p.consumer_id", String.class)
.getResultList();





