I have two classes with one-to-one mappings between them. The User class is read-write. Every user *might* have a Status object. The STATUS table is populated externally (by an stored database procedure) and is read-only as far as my application is concerned.
Both User and Status are cached.
My question is: is there a way to cache the fact that a particular user does not have a Status? I have a page that loads 5 users. 2 of these users do not have a corresponding row in the STATUS table. The first time the page loads I see 5 queries for Status. The second time (and each subsequent time) there are 2 queries for the Status object.
I'd like to remember the fact that Status is missing for those 2 Users and only check again when the cache entry expires.
Is this possible? If not, has anyone come up with a way to do this?
thanks
sam
ps - The User cache timeout is very long as they change very infrequently. The Status cache timeout is much shorter as it changes more frequently (via a stored procedure). The Status class is also lazy... as I frequently don't even care about it.
Hibernate version: 2.1.7
Mapping documents:
Code:
<class name="User" table="USER">
<cache usage="read-write"/>
<id name="id" column="USER_ID">
<generator class="sequence">
<param name="sequence">USER_SEQ</param>
</generator>
</id>
<property name="firstName" column="FIRST_NAME" type="string"/>
<property name="lastName" column="LAST_NAME" type="string"/>
<one-to-one name="status" class="Status"/>
</class>
<class name="Status" table="STATUS" lazy="true">
<cache usage="read-only"/>
<id name="id" column="USER_ID">
<generator class="foreign">
<param name="property">user</param>
</generator>
</id>
<property name="currentStatus" column="STATUS" type="string"/>
<one-to-one name="user" class="User" constrained="true"/>
</class>