forked from mrigor87/CalorieManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJpaUtil.java
More file actions
25 lines (20 loc) · 774 Bytes
/
JpaUtil.java
File metadata and controls
25 lines (20 loc) · 774 Bytes
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
package ru.javawebinar.topjava.repository;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
public class JpaUtil {
@PersistenceContext
private EntityManager em;
public void clear2ndLevelHibernateCache() {
Session s = (Session) em.getDelegate();
SessionFactory sf = s.getSessionFactory();
// sf.evict(User.class);
// sf.getCache().evictEntity(User.class, BaseEntity.START_SEQ);
// sf.getCache().evictEntityRegion(User.class);
sf.getCache().evictQueryRegions();
sf.getCache().evictDefaultQueryRegion();
sf.getCache().evictCollectionRegions();
sf.getCache().evictEntityRegions();
}
}