-->
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.  [ 4 posts ] 
Author Message
 Post subject: Session.load() lazy-loading ALL properties
PostPosted: Mon Feb 11, 2008 7:59 am 
Newbie

Joined: Sat Feb 09, 2008 1:47 am
Posts: 2
Hi. I am using Hibernate and Spring in a project right now and I am having some trouble with Session.load(). There's this object called HibernateTemplate which wraps around Session and helps you control your session (it opens and closes it on every method call).

Since all I need is to load one single object, I think there's no problem using this HibernateTemplate object. It has a load() method just like Session but the thing is that it closes the session before returning the object. So once you get the object back, it is already detached from its Session and you are not able to get ANY of it's properties (not only collections, but ANY of them) without getting a "LazyInitializationException".

So what's the point of having a load() method if it doesn't load your object properties, not even the simple ones? I can understand why Hibernate tries to lazy load collections, but what about Strings, Integers and all those simple properties?

Thanx in advance

Rodrigo

-------------

Hibernate version: 3

Mapping documents:
<hibernate-mapping package="com.corbitecso.coredu.modelo">
<class name="Curso" table="curso">
<id name="idCurso" column="id_curso">
<generator class="increment" />
</id>

<property name="nombre" column="course_name"/>
<property name="descripcion"/>
<set name="estudiantes" table="estudiante_cursos"
inverse="true">
<key column="id_curso" />
<many-to-many column="id_estudiante"
class="com.corbitecso.coredu.modelo.Estudiante" />
</set>
</class>
</hibernate-mapping>


Name and version of the database you are using: mysql 5

The generated SQL (show_sql=true): I think it is generating an SQL which has all those simple properties in it, but still it is not loading them in the object

Debug level Hibernate log excerpt: ¿?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 11, 2008 8:32 am 
Newbie

Joined: Mon Feb 11, 2008 5:46 am
Posts: 5
Actually the session is closed within HibernateTemple class, check the method "public Object execute(HibernateCallback action, boolean exposeNativeSession) throws DataAccessException" within HibernateTemplate class, line 358


Top
 Profile  
 
 Post subject: Well, yes. My fault. :) Still...
PostPosted: Mon Feb 11, 2008 8:50 am 
Newbie

Joined: Sat Feb 09, 2008 1:47 am
Posts: 2
Well, yes. My fault. :)

I think that's what I tried to say when I wrote "it closes the session before returning the (retrieved) object".

So, why retrieving it, closing it's session and the returning it without a single property loaded?

Thanx for your quick reply, by the way :)

Rodrigo


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 11, 2008 9:46 am 
Newbie

Joined: Mon Feb 11, 2008 5:46 am
Posts: 5
I guess you have to ask this question to spring developers, it is spring class afterall that closes the session


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.