休止状態 3.2.5 を使用しています。
DepartmentとTrainingテーブルの間に一対多の関係があります。第 2 レベルのキャッシングが有効になり (EHCache を使用) dept.cfg.xml、データをキャッシングするために および `training.hbm.xml ファイルの両方で以下のエントリが作成されます。
<cache usage="read-only" />
問題の説明
Deptレコードとレコードの両方を取得するために、初めて DB ヒットが行われTrainingます。2 回目Departmentはキャッシュからデータがフェッチされますが、データを取得するためにTrainingDB ヒットが再度行われます - なぜですか? このTrainingデータも、毎回 DB にアクセスするのではなく、キャッシュから取得する必要があります。
これはDept.javaファイルです。
private int deptId;
private String deptName;
private Map trainingDetails;
次のように、 dept.hbm.xmlファイルのマッピングについて言及しました。
//Mappings between POJO and DB Table
<map name="trainingDetails" inverse="false" cascade="delete" lazy="false">
      <key column="DEPT_ID"></key>          
      <map-key formula="ID" type="integer"></map-key>
      <one-to-many class="com.model.Training"/>          
</map>
これは私が試したコードです:
SessionFactory sf = new Configuration().configure("trial.cfg.xml").buildSessionFactory();
    Session session = sf.openSession();
    Dept department = (Dept)session.load(Dept.class, 1);
    //Some business related operations
    session.flush();
    session.close();
            //Some operations
            Session session1 = sf.openSession();        
    Dept department1 = (Dept)session1.load(Dept.class, 1);
    //Here I can see in the console the query for fetching the 
    //training details for the department is getting executed again
    //but the Department details is getting fetched from the Cache - WHY?
    //I want the Training details also to be fetched from the cache.
    session1.flush();
    session1.close();
不足しているものと、これを解決する方法を教えてください。