[JPA & Hibernate] JPQL(Java Persistence Query Language)

원알렉스·2020년 8월 10일
0

JPA

목록 보기
3/16
post-thumbnail
post-custom-banner

깃허브 소스코드
Udemy 강의영상

@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = JpaApplication.class)
public class JPQLTests {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private EntityManager entityManager;

    @Test
    public void findAllWithQuery() {
        Query query = entityManager.createQuery("SELECT C FROM Course C");
        List<?> courses = query.getResultList();
        logger.info(String.format("SELECT C FROM Course C -> %s", courses));
    }

    @Test
    public void findAllWithTypedQuery() {
        TypedQuery<Course> query = entityManager.createQuery("SELECT C FROM Course C", Course.class);
        List<Course> courses = query.getResultList();
        logger.info(String.format("SELECT C FROM Course C -> %s", courses));
    }

    @Test
    public void findAllWithWhere() {
        TypedQuery<Course> query = entityManager.createQuery("SELECT C FROM Course C WHERE name LIKE '%1'", Course.class);
        List<Course> courses = query.getResultList();
        logger.info(String.format("SELECT C FROM Course C WHERE name LIKE '%%1' -> %s", courses));
    }
}
profile
Alex's Develog 🤔
post-custom-banner

0개의 댓글