Hi
I am having problem to cache a object graph.
the object mapping like the following:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.sp.fbb.businessobject.proposal.ProposalHeader" table="FBB_PROPOSAL_HEADER" mutable="false">
<cache usage="read-only" />
<id column="PROPOHDR_ID" name="id" type="java.lang.Long">
<generator class="sequence"/>
</id>
<property column="PROPOHDR_NAME" length="250" name="proposalHeaderName" type="java.lang.String"/>
<property column="PROPOHDR_ORDER" length="22" name="proposalHeaderOrder" not-null="true" type="java.lang.Long"/>
<property column="GOALCTGRY_ID" length="12" name="goalCategoryID" type="java.lang.Long"/>
<property column="IS_MANDATORY" length="1" name="isMandatory" type="java.lang.String"/>
<property column="PROPOTMPL_ID" length="12" name="proposalTemplateID" not-null="true" type="java.lang.Long"/>
<property column="DOCU_ID" length="12" name="documentID" type="java.lang.Long"/>
<bag name="proposalSectionList" table="FBB_PROPOSAL_SECTION" lazy="false" order-by="PROPOSCT_ORDER asc " outer-join="true" >
<key column="PROPOHDR_ID" />
<one-to-many class="com.sp.fbb.businessobject.proposal.ProposalSection" />
</bag>
</class>
</hibernate-mapping>
and
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.sp.fbb.businessobject.proposal.ProposalSection" table="FBB_PROPOSAL_SECTION" mutable="false">
<cache usage="read-only" />
<id column="PROPOSCT_ID" length="12" name="proposalSectionID" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">FBB_PROPOSCT_PK_SEQ</param>
</generator>
</id>
<property column="PROPOHDR_ID" length="12" name="proposalHeaderID" not-null="true" type="java.lang.Long"/>
<property column="PROPOSCT_NAME" length="250" name="proposalSectionName" type="java.lang.String"/>
<property column="PROPOSCT_ORDER" length="22" name="proposalSectionOrder" not-null="true" type="java.lang.Long"/>
<property column="IS_MANDATORY" length="1" name="isMandatory" type="java.lang.String"/>
<property column="PROPO_SAMPLE" length="1024" name="proposalSample" type="java.lang.String"/>
</class>
</hibernate-mapping>
my ehcache mapping is :
<cache name="com.sp.fbb.businessobject.proposal.ProposalHeader"
maxElementsInMemory="100"
eternal="false"
timeToIdleSeconds="60000"
timeToLiveSeconds="60000"
overflowToDisk="true"
/>
<cache name="com.sp.fbb.businessobject.proposal.ProposalSection"
maxElementsInMemory="100"
eternal="false"
timeToIdleSeconds="60000"
timeToLiveSeconds="60000"
overflowToDisk="true"
/>
In my test case, I am using hibernate.load() , the test result is
================== 1 ========================
Opened hibernate session.
Hibernate: select proposalhe0_.PROPOHDR_ID as PROPOHDR1_1_, proposalhe0_.PROPOHDR_NAME as PROPOHDR2_1_, proposalhe0_.PROPOHDR_ORDER as PROPOHDR3_1_, proposalhe0_.GOALCTGRY_ID as GOALCTGR4_1_, proposalhe0_.IS_MANDATORY as IS_MANDA5_1_, proposalhe0_.PROPOTMPL_ID as PROPOTMP6_1_, proposalhe0_.DOCU_ID as DOCU_ID1_, proposalse1_.PROPOSCT_ID as PROPOSCT1___, proposalse1_.PROPOHDR_ID as PROPOHDR2___, proposalse1_.PROPOSCT_ID as PROPOSCT1_0_, proposalse1_.PROPOHDR_ID as PROPOHDR2_0_, proposalse1_.PROPOSCT_NAME as PROPOSCT3_0_, proposalse1_.PROPOSCT_ORDER as PROPOSCT4_0_, proposalse1_.IS_MANDATORY as IS_MANDA5_0_, proposalse1_.PROPO_SAMPLE as PROPO_SA6_0_ from FBB_PROPOSAL_HEADER proposalhe0_, FBB_PROPOSAL_SECTION proposalse1_ where proposalhe0_.PROPOHDR_ID=? and proposalhe0_.PROPOHDR_ID=proposalse1_.PROPOHDR_ID(+)
Closed hibernate session.
================== 2 ========================
Opened hibernate session.
Hibernate: select proposalse0_.PROPOSCT_ID as PROPOSCT1___, proposalse0_.PROPOHDR_ID as PROPOHDR2___, proposalse0_.PROPOSCT_ID as PROPOSCT1_0_, proposalse0_.PROPOHDR_ID as PROPOHDR2_0_, proposalse0_.PROPOSCT_NAME as PROPOSCT3_0_, proposalse0_.PROPOSCT_ORDER as PROPOSCT4_0_, proposalse0_.IS_MANDATORY as IS_MANDA5_0_, proposalse0_.PROPO_SAMPLE as PROPO_SA6_0_ from FBB_PROPOSAL_SECTION proposalse0_ where proposalse0_.PROPOHDR_ID=? order by proposalse0_.PROPOSCT_ORDER asc
Closed hibernate session.
================== 3 ========================
Opened hibernate session.
Hibernate: select proposalse0_.PROPOSCT_ID as PROPOSCT1___, proposalse0_.PROPOHDR_ID as PROPOHDR2___, proposalse0_.PROPOSCT_ID as PROPOSCT1_0_, proposalse0_.PROPOHDR_ID as PROPOHDR2_0_, proposalse0_.PROPOSCT_NAME as PROPOSCT3_0_, proposalse0_.PROPOSCT_ORDER as PROPOSCT4_0_, proposalse0_.IS_MANDATORY as IS_MANDA5_0_, proposalse0_.PROPO_SAMPLE as PROPO_SA6_0_ from FBB_PROPOSAL_SECTION proposalse0_ where proposalse0_.PROPOHDR_ID=? order by proposalse0_.PROPOSCT_ORDER asc
Closed hibernate session.
Question:
Why the ehcache not cache the parent object with the collections?
from the testing result it seems the chilren collection is loaded from DB but the parent object is cached.
How can I cache the entire object graphe?
Thanks in advance
|