JPQL에서 엔티티를 직접 사용하면 SQL에서 해당 엔티티의 기본 키 값을 사용한다.
JPQL
select count(m.id) from Member m // 엔티티의 아이디를 사용
select count(m) from Member m // 엔티티를 직접 사용
SQL (위의 JPQL 모두 아래의 SQL을 실행)
select count(m.id) as cnt from Member m
String jpql = "select m from Member m where m = :member";
List<Member> resultList = em.createQuery(jpql, Member.class)
.setParameter("member", member)
.getResultList();
// 실행된 SQL
select m.* from Member m where m.id = ?
Team team = em.find(Team.class, 1L);
String query = "select m from Member m where m.team = :team";
List<Member> resultList = em.createQuery(query, Member.class)
.setParameter("team", team)
.getResultList();
// 실행된 SQL
select m.* from Member m where m.team_id = ?