I'm trying to solve a (quite unconventional) lazy many-to-one mapping. I found a lot of similar posts but none addressed my requirements completely.
I'd like to provide Class
Request with a
lazy many-to-one relationship to an immutable, read-only entity
Cert.
Cert however is not a real table but mapped by a custom SQL loader query.
The two classes are linked by the request's property
requestNumber. This property is not a foreign key, since it's an optional property on the request. A
Cert object is created asynchronous for each request.
Now, when I'm retrieving a list of
Request objects, Hibernate executes the custom SQL loader query for each request in order to load an associated
Cert object. Since I mapped the many-to-one association as lazy I'd expect Hibernate would only load a
Certobject when it is accessed.
Is there anything I need to adjust in the mapping or will Hibernate always do the lookup on the many-to-one association regardless of the lazy-setting?
Hibernate version:
3.2.5
Mapping documents:
Class Request:
Code:
<class name="Request" table="idstorerequest">
<id name="id">
<generator class="sequence">
<param name="sequence">request_id_seq</param>
</generator>
</id>
<version name="version" access="field" type="long" column="hibernate_version" />
<property name="..." />
...
<property name="requestNumber" type="long" unique="true" />
<many-to-one name="cert" column="requestNumber" class="Cert"
not-null="false" insert="false" update="false" foreign-key="none" not-found="ignore" lazy="proxy"/>
</class>
Class Cert:
Code:
<class name="Cert" mutable="false" lazy="true">
<subselect> expensive SQL </subselect>
<id name="requestNumber" column="requestnumber" />
<property ... />
<loader query-ref="loadCert" /> <!-- expensive SQL loader query -->
</class>
Name and version of the database you are using:
PostgreSQL 8.2