일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- HttpMessageConverters
- 백트래킹
- Application Event
- AuthenticationPrincipal
- 알고리즘
- 브루트포스
- 다익스트라
- WebApplication Type
- 외부설정
- 리소스 서버
- application.properties
- OAuth2
- EnableAutoConfiguration
- 리소스핸들러
- Application Runner
- HATEOAS
- @ConfigurationProperties
- Application Argument
- rest api
- JPA
- 백기선
- JsonSerializer
- 스프링부트
- 스프링 부트
- 정적 리소스
- Spring Security
- cors
- @Profile
- webjar
- 백준
- Today
- Total
아카이브
[스프링 데이터 JPA] JPA 프로그래밍 7: Query 본문
JPQL (HQL)
- Java Persistence Query Language / Hibernate Query Language
- 데이터베이스 테이블이 아닌, 엔티티 객체 모델 기반으로 쿼리 작성
- JPA 또는 하이버네이트가 해당 쿼리를 SQL로 변환해서 실행함
- https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#hql
Hibernate ORM 5.2.18.Final User Guide
Fetching, essentially, is the process of grabbing data from the database and making it available to the application. Tuning how an application does fetching is one of the biggest factors in determining how an application will perform. Fetching too much dat
docs.jboss.org
Criteria
https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#criteria
Hibernate ORM 5.2.18.Final User Guide
Fetching, essentially, is the process of grabbing data from the database and making it available to the application. Tuning how an application does fetching is one of the biggest factors in determining how an application will perform. Fetching too much dat
docs.jboss.org
Native Query
https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#sql
Hibernate ORM 5.2.18.Final User Guide
Fetching, essentially, is the process of grabbing data from the database and making it available to the application. Tuning how an application does fetching is one of the biggest factors in determining how an application will perform. Fetching too much dat
docs.jboss.org
QueryRunner를 통한 테스트
@Component
@Transactional
public class QueryRunner implements ApplicationRunner {
@PersistenceContext
EntityManager entityManager;
@Override
public void run(ApplicationArguments args) throws Exception {
/**
* JPQL - 타입세이프 X
*/
TypedQuery<Post> query = entityManager.createQuery("SELECT p FROM Post AS p", Post.class); // Post는 엔티티 이름이다.
List<Post> jpqlResultList = query.getResultList();
jpqlResultList.forEach(p -> System.out.println(p.toString()));
/**
* Criteria - 타입세이프 O
* */
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Post> criteriaQuery = builder.createQuery(Post.class);
Root<Post> from = criteriaQuery.from(Post.class);
criteriaQuery.select(from);
List<Post> criteriaResultList = entityManager.createQuery(criteriaQuery).getResultList();
criteriaResultList.forEach(p -> System.out.println(p.toString()));
/**
* Native Query
* */
List<Post> nativeQueryResultList = entityManager.createNativeQuery("SELECT * FROM POST", Post.class).getResultList();
nativeQueryResultList.forEach(p -> System.out.println(p.toString()));
}
}
'Spring > 스프링 데이터 JPA' 카테고리의 다른 글
[스프링 데이터 JPA] 스프링 데이터 Common 1.레포지토리 (테스트) (0) | 2021.01.16 |
---|---|
[스프링 데이터 JPA] 스프링 데이터 JPA 소개 및 원리 (0) | 2021.01.10 |
[스프링 데이터 JPA] JPA 프로그래밍 6: Fetch (0) | 2021.01.10 |
[스프링 데이터 JPA] JPA 프로그래밍 5. Cascade (0) | 2021.01.10 |
[스프링 데이터 JPA] JPA 프로그래밍 4. 1대다(관계) 맵핑 (0) | 2021.01.10 |