Hello,
i have a question concerning the second level cache and caching collections. I have a business object that has a list of security Objects. In the first step i want to load all security Objects
into the second level cache, which works fine. The objects are stored
in the second level cache using their primary key. After that i want to
load all my business objects from the db. this works but the security objects are still loaded from the db and are not taken
from the second level cache, even though all the securities are
available in the second level cache and i am using the collection-cache
mapping. Looking at the hibernate log i can see that hibernate checks
the second level cache for the security objects. however it is using the
primary key of the business object to find the securities (of my
securities set), which
does not work, of course. what i do not understand is why it is using the
primary key of business object ? when using that pk it can never find
more than one security object because the pk has to be unique.
this way my set of securities can never have more than one element.
is it a problem that i have a composite-id for both classes which do
not have exactly the same attribute / values ? both keys share the
kontoNrSub and the kontoNr attributes (the security class has an
additional attribute). I expected that hibernate would take the defined
key columns from the set and create a new security primary key
(which would be incomplete, because of the one missing attribute in
the association), which hibernates uses to get all securites from the
second level cache which match that partial primary key ?
I do not know if this is possible at all ?
any ideas ?
thanks in advance,
Andreas
Hibernate version:
3.0.5
Mapping documents:
Code:
hibernate.cfg.xml :
<class-cache class="Business" usage="read-write"/>
<class-cache class="Security" usage="read-write"/>
<collection-cache collection="Business.securities" usage="read-write"/>
mapping files :
<hibernate-mapping auto-import="false">
<class name="Business" table="Business_VW" lazy="false">
<composite-id name="id" class="BusinessPK">
<key-property name="kontoNr" type="java.lang.Long">
<column name="KONTO_NR" scale="15" precision="0" not-null="true" sql-type="NUMBER" />
</key-property>
<key-property name="kontoNrSub" type="java.lang.Long">
<column name="KONTO_NR_SUB" scale="15" precision="0" not-null="true" sql-type="NUMBER" />
</key-property>
</composite-id>
<set name="securities" lazy="true" outer-join="false" cascade="save-update" batch-size="200">
<key>
<column name="KONTO_NR" scale="15" precision="0" not-null="false" />
<column name="KONTO_NR_SUB" scale="15" precision="0" not-null="false" />
</key>
<one-to-many class="Security" />
</set>
</class>
</hibernate-mapping>
<hibernate-mapping auto-import="false">
<class name="Security" table="Security_VW" lazy="false">
<composite-id name="id" class="SecurityPK">
<key-property name="SicherungsId" type="java.lang.String">
<column name="SICHERUNGS_ID" scale="100" precision="0" not-null="true" sql-type="VARCHAR2" />
</key-property>
<key-property name="KontoNr" type="java.lang.Long">
<column name="KONTO_NR" scale="15" precision="0" not-null="true" sql-type="NUMBER" />
</key-property>
<key-property name="KontoNrSub" type="java.lang.Long">
<column name="KONTO_NR_SUB" scale="15" precision="0" not-null="true" sql-type="NUMBER" />
</key-property>
</composite-id>
<!-- .... some properties ... -->
</class>
</hibernate-mapping>