JPQL 타입 표현과 기타 식
타입
문자
숫자
Boolean
ENUM
select m.username, 'hello', true
from Member m
where m.type = jpql.MemberType.ADMINEntity
기타 식
Last updated
select m.username, 'hello', true
from Member m
where m.type = jpql.MemberType.ADMINLast updated
class JpaMain {
public static void main(String[] args) {
String query = "select m.username, 'hello', true from Member m " +
// 특정 enum 타입 조회
"where m.type = jpql.MemberType.USER";
List<Object[]> result = em.createQuery(query)
.getResulstList();
for (Object[] objects : result) {
System.out.println("objects " + objects[0]);
System.out.println("objects " + objects[1]);
System.out.println("objects " + objects[2]);
}
}
}object = teamA
// 그냥 이렇게 입력한 문자를 그대로 뽑을 수도 있다.
object = hello
object = trueclass JpaMain {
public static void main(String[] args) {
String query = "select m.username, 'hello', true from Member m " +
// 패키지 이름이 너무 길면 이렇게 표현할 수 있다.
"where m.type = :userType";
List<Object[]> result = em.createQuery(query)
// userType에 원하는 enum을 세팅한다.
.setParameter("userType", MemberType.ADMIN)
.getResulstList();
for (Object[] objects : result) {
System.out.println("objects " + objects[0]);
System.out.println("objects " + objects[1]);
System.out.println("objects " + objects[2]);
}
}
}TypedQuery<Item> query=em.createQuery("select i from Item i where type(i) = 'Book'",Item.class);