2016-03-22 23 views
0

İki tablo için ikinci düzey önbellek kullanmaya çalışıyorum, ancak yalnızca bir tablo için çalışıyor. Ehcache Hazırda Bekletme Bir tabloda yalnızca bir tablo için çalışıyor

<?xml version="1.0"?> 
<ehcache> 
<defaultCache 
    maxElementsInMemory="100" 
    eternal="false" 
    timeToIdleSeconds="120" 
    timeToLiveSeconds="200" /> 

    <cache name="com.cni.Employee" 
    maxElementsInMemory="100" 
    eternal="false" 
    timeToIdleSeconds="10" 
    timeToLiveSeconds="200" /> 

    <cache name="com.cni.Person" 
    maxElementsInMemory="100" 
    eternal="false" 
    timeToIdleSeconds="10" 
    timeToLiveSeconds="200" /> 

</ehcache> 

Sadece "Çalışan" sınıfı önbelleğe ediliyor şöyle My ehcache.xml yapılandırmasıdır. Sınıf için ilk kez sadece bir SQL sorgusu görebiliyordum. Ancak "Kişi" sınıfı için, web hizmetine her vurduğumda, her zaman SQL sorgusunu gösterir. Başka bir şey yapılandırmam gerekiyor mu?

Benim Kişi sınıfı

@Cache(usage = CacheConcurrencyStrategy.READ_ONLY) 
@Entity 
@Table(name = "person") 
public class Person { 
@Override 
public String toString() { 
    return "Person [id=" + id + ", userId=" + userId 
      + ", courseId=" + courseId + ", courseValue=" + courseValue 
      + "]"; 
} 
@Id 
@GeneratedValue(strategy=GenerationType.AUTO) 
private int id; 
private String userId; 
private String courseId; 
private String courseValue; 

Benim seçme sorgusu kodu

public JSONObject getCourseDetails(String id) { 

    System.setProperty("net.sf.ehcache.skipUpdateCheck", "true"); 
    JSONObject obj = new JSONObject();  
    try (Session session = factory.openSession()) { 
     String hql = "FROM Person E WHERE E.userId = "+id; 
     Query query = session.createQuery(hql); 
     List<?> results = query.list(); 
     Gson gson = new Gson(); 
     String jsonCourseList = gson.toJson(results); 
     System.out.println("Course JSON Data: " + jsonCourseList); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    return obj; 
} 
+0

Çalışan için kullandığınız sorgu nedir? –

+0

@DraganBozanovic Employee emp = session.load (Çalışan, sınıf, kimlik); Bu, Çalışan sınıfı için kullanıyorum sorgusudur – Syed

cevap

0

JPQL/HQL daima veritabanında yürütülür olduğunu. Daha sonra varlıklar, sorgu sonuç kümesindeki kimlikleri temelinde ikinci düzey önbellekten getirilir.

session.load yönteminde, varlık doğrudan sağlanan kimlikle ikinci düzey önbellekten getirilir. Sorgu veritabanında çalıştırılmaya gerek yoktur, çünkü kimlik zaten bilinir.

İlgili konular