문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
|
java:jpa:cache [2014/06/07 23:46] kwon37xi |
java:jpa:cache [2015/10/17 12:07] (현재) kwon37xi |
||
|---|---|---|---|
| 줄 1: | 줄 1: | ||
| ====== JPA Second Level Cache ====== | ====== JPA Second Level Cache ====== | ||
| + | * [[java: | ||
| * Hibernate 4 기반으로 살펴보는 JPA2 Second Level Cache. | * Hibernate 4 기반으로 살펴보는 JPA2 Second Level Cache. | ||
| * 아직까지 살펴본바로는, | * 아직까지 살펴본바로는, | ||
| + | * 아래 나오는 Property Key의 대부분은 [[https:// | ||
| - | ===== Entity Cache ===== | + | ===== Evict All ===== |
| - | <code java> | + | 현재 Hibernate 구현체(4.3)은 JPA의 Cache.evictAll() 호출시에 모든 Region을 evict하지 않고 오로지 Entity 관련 |
| - | @Entity | + | |
| - | @Table(name = " | + | |
| - | @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE, | + | |
| - | public class Book implements Serializable { | + | |
| - | .... | + | |
| - | } | + | |
| - | </ | + | |
| + | 전체 리젼을 다 evict하려면 Hibernate의 '' | ||
| + | 관련 구현은 [[https:// | ||
| + | |EntityManagerFactoryImpl.java]]에 있다. | ||
| - | ===== Query Cache ===== | + | <code java> |
| - | * '' | + | // JPA 2.0사용시 |
| - | TypedQuery< | + | HibernateEntityManagerFactory hemf = (HibernateEntityManagerFactory)entityManagerFactory; |
| - | query.setParameter(" | + | org.hibernate.Cache cache = hemf.getSessionFactory().getCache(); |
| - | query.setHint("org.hibernate.cacheable", | + | // JPA 2.1 사용시 |
| - | query.setHint(" | + | SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class) |
| - | </ | + | org.hibernate.Cache cache = sessionFactory.getCache(); |
| - | * '' | + | // 전체 eviction |
| - | @NamedQuery(name = "Book.byEdition", | + | cache.evictEntityRegions(); |
| - | query = "from Book where edition=: | + | cache.evictQueryRegions(); |
| - | hints = { | + | cache.evictCollectionRegions(); |
| - | @QueryHint(name = " | + | |
| - | | + | |
| - | } | + | |
| - | ) | + | |
| - | public class Book implements Serializable { | + | |
| - | .... | + | |
| - | } | + | |
| </ | </ | ||
| + | |||
| + | ===== 참고 ===== | ||
| + | * [[http:// | ||
| + | |||