Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing nHibernate secondary cache for a many-to-one reference
    primarykey
    data
    text
    <p>I'm trying to get nHibernate to use second-level cache with a many-to-one relationship, however I can't find any clear explanation on how to set it up correctly. I found this <a href="https://stackoverflow.com/questions/6893831/how-to-get-nhibernate-to-cache-tables-referenced-via-many-to-one-is-my-config">How to get nhibernate to cache tables referenced via many-to-one - is my config correct?</a>, but the example sJHonny provided is for one-to-many and it's not working for me when I adopt it. There are other posts going over this subject, but none of them are specific enough.</p> <p>The XML config I provide works (I had to edit dramatically, so "hopefully" works), but lookup objects are being cached only when they are retrieved as DataObject is queried. I'd like to know 1) where/how to preload the LookupObject collection? 2) what if I assign this collection to a region and set expiration, then where/how do I reload the cache again? 3) how to change the DataObject's hbm.xml such that nHibernate doesn't generate a join with the LOOKUP table, i.e. such that lookup objects always come from the secondary cache, only getting the DATA.LOOKUP_ID from the db, not the LOOKUP.NAME?</p> <p>LookupObject.hbm.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="BusinessObjects" assembly="BusinessObjects"&gt; &lt;class name="LookupObject" table="LOOKUP" mutable="false" batch-size="20"&gt; &lt;cache usage="read-only" /&gt; &lt;id name="Id" column="ID" /&gt; &lt;property name="Name" column="NAME" /&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>DataObject.hbm.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="BusinessObjects" assembly="BusinessObjects"&gt; &lt;class name="DataObject" table="DATA" mutable="false"&gt; &lt;composite-id&gt; &lt;key-property name="Id" column="ID"/&gt; &lt;key-property name="Date" column="DATE" type="Date"/&gt; &lt;/composite-id&gt; &lt;many-to-one name="LookupObject" not-null="true" column="LOOKUP_ID" fetch="join"&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload