Hibernate version: 2.1.7
Hi all!
I'm tourble, i have a little question.
Suppose that i have a normal lazy initialization like this
<class
name="it.axiosinformatica.webward.hibernate.TprofProfili"
table="TPROF_PROFILI"
>
<id
name="iprofid"
type="java.lang.Integer"
column="IPROFID"
>
<generator class="assigned" />
</id>
<property
name="iprofcodice"
type="java.lang.String"
column="IPROFCODICE"
length="5"
>
</property>
<property
name="iprofdescr"
type="java.lang.String"
column="IPROFDESCR"
length="40"
>
</property>
<!-- Associations -->
<!-- bi-directional one-to-many association to TacceAccessi -->
<set
name="tacceAccessis"
lazy="true"
inverse="true"
cascade="none"
>
<key>
<column name="IPROFID" />
</key>
<one-to-many
class="it.axiosinformatica.webward.hibernate.TacceAccessi"
/>
</set>
</class>
All right?
Now, i load the parent class TprofProfili in this mode
public class FinderUtil {
public Object findById(Class theClass, Integer id)
throws HibernateException {
net.sf.hibernate.Session hibSession = it.axiosinformatica.webward.hibernate.util.Session.currentSession();
Object retval = hibSession.load(theClass, id);
it.axiosinformatica.webward.hibernate.util.Session.closeSession();
return retval;
}
I have used the reflection (theClass is TprofProfili).
All seems to work fine (and i have close the session).
And the problem:
In the application i need to load TprofProfili's child table (tacceAccessis).
Good!
I do this:
net.sf.hibernate.Session hibSession = it.axiosinformatica.webward.hibernate.util.Session.currentSession();
Set s = tprofProfili.getTacceAccessis();
it.axiosinformatica.webward.hibernate.util.Session.closeSession();
It shoud works, but hibernate retrive me a LazyInitializationException.
Why? Can i load childs in a second moment? Why not?
Somebody helps me.
Thanks
P.S. Sorry for my bad english!
|