hibernate 325, ehcache 1.3 && 1.5beta1
Using second-level cache and query cache with ehcache. Running a query 2x in a row on a simple setup, bi-directional association between 2 classes mapped via a set. Dprog (w/ composite-id) has a set of DprogReqs.
On first query, everything is good and cached perfectly. On second query, it finds the first member of the collection child-object in the cache but its foreign-key values have become null, can't find null composite-id parent values in cache so it tries to load it from the db but it doesn't exist.
logs. It caches DprogReq#267 (first one in ordered set) correctly with values set for all the foreign-key attributes. instid, instcd, instidq...
Code:
09 Jun 2008 12:17:30 : [DEBUG] org.hibernate.engine.TwoPhaseLoad - resolving associations for [dars.apis.requirement.DprogReq#267]
09 Jun 2008 12:17:30 : [DEBUG] org.hibernate.event.def.DefaultLoadEventListener - loading entity: [dars.apis.requirement.Dprog#component[instidq,instid,instcd,dprog,dpfyt]{dpfyt=000000, instid=EDAG, instcd=, instidq=73, dprog=ACCTBA}]
09 Jun 2008 12:17:30 : [DEBUG] org.hibernate.event.def.DefaultLoadEventListener - attempting to resolve: [dars.apis.requirement.Dprog#component[instidq,instid,instcd,dprog,dpfyt]{dpfyt=000000, instid=EDAG, instcd=, instidq=73, dprog=ACCTBA}]
09 Jun 2008 12:17:30 : [DEBUG] org.hibernate.event.def.DefaultLoadEventListener - resolved object in session cache: [dars.apis.requirement.Dprog#component[instidq,instid,instcd,dprog,dpfyt]{dpfyt=000000, instid=EDAG, instcd=, instidq=73, dprog=ACCTBA}]
09 Jun 2008 12:17:30 : [DEBUG] org.hibernate.engine.TwoPhaseLoad - adding entity to second-level cache: [dars.apis.requirement.DprogReq#267]
09 Jun 2008 12:17:30 : [DEBUG] org.hibernate.cache.NonstrictReadWriteCache - Caching: dars.apis.requirement.DprogReq#267
09 Jun 2008 12:17:30 : [DEBUG] org.hibernate.engine.TwoPhaseLoad - done materializing entity [dars.apis.requirement.DprogReq#267]
then when I run the query again I get this. It finds DprogReq#267 in the cache, loads it, but its foreign-key references are null, so it tries to load its parent object by its composite-id with all null values which doesn't exist.
Code:
09 Jun 2008 12:17:30 : [DEBUG] net.sf.ehcache.store.MemoryStore - dars.apis.requirement.Dprog.dprogReqsCache: dars.apis.requirement.Dprog.dprogReqsMemoryStore hit for dars.apis.requirement.Dprog.dprogReqs#dars.apis.requirement.DprogPK@fdc6cdac [instidq='73' instid='EDAG' instcd='' dprog='ACCTBA' dpfyt='000000' ]
09 Jun 2008 12:17:30 : [DEBUG] org.hibernate.cache.NonstrictReadWriteCache - Cache hit
09 Jun 2008 12:17:30 : [DEBUG] org.hibernate.event.def.DefaultLoadEventListener - loading entity: [dars.apis.requirement.DprogReq#267]
09 Jun 2008 12:17:30 : [DEBUG] org.hibernate.event.def.DefaultLoadEventListener - attempting to resolve: [dars.apis.requirement.DprogReq#267]
09 Jun 2008 12:17:30 : [DEBUG] org.hibernate.cache.NonstrictReadWriteCache - Cache lookup: dars.apis.requirement.DprogReq#267
09 Jun 2008 12:17:30 : [DEBUG] org.hibernate.cache.EhCache - key: dars.apis.requirement.DprogReq#267
09 Jun 2008 12:17:30 : [DEBUG] net.sf.ehcache.store.MemoryStore - dars.apis.requirement.DprogReqCache: dars.apis.requirement.DprogReqMemoryStore hit for dars.apis.requirement.DprogReq#267
09 Jun 2008 12:17:30 : [DEBUG] org.hibernate.cache.NonstrictReadWriteCache - Cache hit
09 Jun 2008 12:17:30 : [DEBUG] org.hibernate.event.def.DefaultLoadEventListener - assembling entity from second-level cache: [dars.apis.requirement.DprogReq#267]
09 Jun 2008 12:17:30 : [DEBUG] org.hibernate.event.def.DefaultLoadEventListener - loading entity: [dars.apis.requirement.Dprog#component[instidq,instid,instcd,dprog,dpfyt]{dpfyt=null, instid=null, instcd=null, instidq=null, dprog=null}]
09 Jun 2008 12:17:30 : [DEBUG] org.hibernate.event.def.DefaultLoadEventListener - attempting to resolve: [dars.apis.requirement.Dprog#component[instidq,instid,instcd,dprog,dpfyt]{dpfyt=null, instid=null, instcd=null, instidq=null, dprog=null}]
09 Jun 2008 12:17:30 : [DEBUG] org.hibernate.cache.NonstrictReadWriteCache - Cache lookup: dars.apis.requirement.Dprog#dars.apis.requirement.DprogPK@4643c825 [instidq='null' instid='null' instcd='null' dprog='null' dpfyt='null' ]
09 Jun 2008 12:17:30 : [DEBUG] org.hibernate.cache.EhCache - key: dars.apis.requirement.Dprog#dars.apis.requirement.DprogPK@4643c825 [instidq='null' instid='null' instcd='null' dprog='null' dpfyt='null' ]
09 Jun 2008 12:17:30 : [DEBUG] net.sf.ehcache.store.MemoryStore - dars.apis.requirement.DprogCache: dars.apis.requirement.DprogMemoryStore miss for dars.apis.requirement.Dprog#dars.apis.requirement.DprogPK@4643c825 [instidq='null' instid='null' instcd='null' dprog='null' dpfyt='null' ]
09 Jun 2008 12:17:30 : [DEBUG] net.sf.ehcache.Cache - dars.apis.requirement.Dprog cache - Miss
09 Jun 2008 12:17:30 : [DEBUG] org.hibernate.cache.EhCache - Element for dars.apis.requirement.Dprog#dars.apis.requirement.DprogPK@4643c825 [instidq='null' instid='null' instcd='null' dprog='null' dpfyt='null' ] is null
09 Jun 2008 12:17:30 : [DEBUG] org.hibernate.cache.NonstrictReadWriteCache - Cache miss
09 Jun 2008 12:17:30 : [DEBUG] org.hibernate.event.def.DefaultLoadEventListener - object not resolved in any cache: [dars.apis.requirement.Dprog#component[instidq,instid,instcd,dprog,dpfyt]{dpfyt=null, instid=null, instcd=null, instidq=null, dprog=null}]
09 Jun 2008 12:17:30 : [DEBUG] org.hibernate.persister.entity.AbstractEntityPersister - Fetching entity: [dars.apis.requirement.Dprog#component[instidq,instid,instcd,dprog,dpfyt]{dpfyt=null, instid=null, instcd=null, instidq=null, dprog=null}]
parent class, Dprog has caching turned on, collection set Dprog.dprogReqs has caching turned on, click class DprogReq has caching turned on all nonstrict-read-write.
relative mapping sections below
parent class: Dprog
Code:
<class name="dars.apis.requirement.Dprog" table="dprog" lazy="false"
>
<cache usage="nonstrict-read-write"/>
<composite-id name="comp_id" class="dars.apis.requirement.DprogPK">
<key-property
name="instidq"
column="instidq"
type="dars.apis.common.dao.hibernate.type.RightTrimmedStringUserType2"
length="2"
>
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
<meta attribute="property-type">java.lang.String</meta>
</key-property>
<key-property
name="instid"
column="instid"
type="dars.apis.common.dao.hibernate.type.RightTrimmedStringUserType8"
length="8"
>
...
<set
name="dprogReqs"
cascade="all"
lazy="false"
order-by="user_seq_no asc"
inverse="true"
>
<cache usage="nonstrict-read-write"/>
<key>
<column name="instidq" length="2" not-null="true" />
<column name="instid" length="8" not-null="true" />
<column name="instcd" length="3" not-null="true" />
<column name="dprog" length="15" not-null="true" />
<column name="dpfyt" length="6" not-null="true" />
</key>
<one-to-many class="dars.apis.requirement.DprogReq"/>
</set>
child class: DprogReq
Code:
<class
name="dars.apis.requirement.DprogReq"
table="dprog_req"
lazy="false"
>
<cache usage="nonstrict-read-write"/>
<id
name="intSeqNo"
type="java.lang.Integer"
column="int_seq_no"
>
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
<generator class="native">
<param name="sequence">dprog_seq_no</param>
</generator>
</id>
<many-to-one name="dprog" class="dars.apis.requirement.Dprog" fetch="select">
<column name="instidq" length="2" not-null="true" />
<column name="instid" length="8" not-null="true" />
<column name="instcd" length="3" not-null="true" />
<column name="dprog" length="15" not-null="true" />
<column name="dpfyt" length="6" not-null="true" />
</many-to-one>
..