✔ 깃허브 소스코드
✔ 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));
}
}