İ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;
}
Çalışan için kullandığınız sorgu nedir? –
@DraganBozanovic Employee emp = session.load (Çalışan, sınıf, kimlik); Bu, Çalışan sınıfı için kullanıyorum sorgusudur – Syed