hello everyone!
i need a little architectural advice concerning lazy loading.
(see mapping files at the bottom).
my class "asset" is used to basically hold a blob of an image.
the other class "record" has a list of "assets".
now, i don't want to populate the blobs in "asset" when an instance is
loaded from the db (obviously because it's slow and takes up much mem).
my problem: if i set the list or the blob-properties to be lazy,
i get an exception because the session is already closed when i later
try to access them.
that's because i'm running hibernate from spring.
now what can i do?
is there another way of making them lazy?
do i have to manually load the blobs when i need them
and remove all logical connections in the classes?
can i make hibernate instantiate the "assets" excluding the blobs?
(kind of "projection at creation time")
thank you very much for your help!
felix
Hibernate version:
3.0.5
Mapping documents:
*** note: some properties are omitted for the sake of clarity ***
<hibernate-mapping default-lazy="false">
<class name="Record" table="record">
<id name="id" column="RECORD_ID">
<generator class="native"/>
</id>
<list name="assets" cascade="all-delete-orphan" lazy="false">
<key column="RECORD_ID"/>
<list-index column="asset_order"/>
<one-to-many class="Asset"/>
</list>
</class>
</hibernate-mapping>
---
<hibernate-mapping default-lazy="false">
<class name="Asset" table="asset">
<id name="id" column="ASSET_ID">
<generator class="native"/>
</id>
<property name="thumbnailBlob" lazy="true" column="thumbnail_blob" type="java.sql.Blob" length="65538"/>
<property name="previewBlob" lazy="true" column="preview_blob" type="java.sql.Blob" length="65538"/>
<property name="fullBlob" lazy="true" column="full_blob" type="java.sql.Blob" length="268435456"/> <!-- 256 MB -->
</class>
</hibernate-mapping>
|