0
2つのテーブルに対して2番目のレベルのキャッシュを使用しようとしていますが、1つのテーブルに対してのみ動作しています。 EhcacheはHibernate内の1つのテーブルに対してのみ動作します
<?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>
のみ「従業員」クラスがキャッシュされている次のように私のehcache.xml設定です。クラスの初めてのSQLクエリは1つしか見ることができませんでした。しかし、 "Person"クラスでは、毎回WebサービスにアクセスしたときにSQLクエリを常に表示します。他の設定が必要ですか?
私のPersonクラスは
@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;
私の選択クエリコード
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;
}
'Employee'に使用するクエリは何ですか? –
@DraganBozanovic従業員emp = session.load(Employee.class、id);これはEmployeeクラスに使用しているクエリです – Syed