-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: lazy blob loading with spring / closed session
PostPosted: Sun Mar 19, 2006 2:17 pm 
Newbie

Joined: Wed Sep 14, 2005 5:13 pm
Posts: 13
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>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 20, 2006 6:44 am 
Newbie

Joined: Wed Mar 15, 2006 9:15 am
Posts: 2
Can you give any details about how you are accessing "record" and the set of "asset"?

Probably (I'm guessing now :) you are using a DAO which extends HibernateDaoSupport to get the "record" and outside the DAO you are trying to access the set of "asset". BUT... the session is opened when you call the DAO and closed when you exit. If you want to keep the session opened you should use a OpenSessionInView filter or HibernateInterceptor. Using these, the session is opened when you call the service layer and closed when you exit to presentation layer.

I hope this helps,

José Luis.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.