Completely, I agree with you. Moreover, in my example, when you create a new
session, you have to reattach the main object (employee) and its dependencies
(company). So, if you want to update the "employee", you should do:
---------------------------------------------------
Session session = HibernateFactory.getCurrentSession();
Employee employee = session.load(getEmployeeId());
Company company = session.load(getCompanyId());
employee.setCompany(company);
session.save(employee); // I'm not sure of the syntax.
---------------------------------------------------
What is your opinion about it Markus ?
Did
----- Original Message -----
From: "Markus Eberle" <[EMAIL PROTECTED]>
To: "Tapestry users" <[email protected]>; "Didier LAFFORGUE"
<[EMAIL PROTECTED]>
Cc: "Tapestry users" <[email protected]>; "Juan Esteban Maya"
<[EMAIL PROTECTED]>
Sent: Wednesday, May 18, 2005 2:05 PM
Subject: Re: Hibernate + Spring: LazyInitializationException
> Zitat von Didier LAFFORGUE <[EMAIL PROTECTED]>:
>
> >
> > I think that the LazyInitializationException occurs when you try to access a
> > property of your object outside the hibernate session.
> > In fact, imagine you have 2 mapped objects: employee and company => in this
> > example, an employee has only one company.
> > First of all, you load the employee with the id 1. In the lazy mode, the
> > associated company is not loaded.
> > If you do not close the current hibernate session, if you do a
> > "employee.getCompany()", hibernate will use the session to load the company
> > object.
> > BUT if you close the session and after if you do the "employee.getCompany()"
> > statement, you'll get the LazyInitializationException.
> > The solution would be to keep the hibernate session in the session scope but
> > I find this solution very dirty.
>
> This _is_ very dirty.
>
> > Another solution is to create the session
> > when the page begins to render and to close it when the rendering is
> > finished
> > (not tested so....).
>
> In most cases you can use the OpenSessionInViewFilter (i think this is the
> name)
> from spring.
> The problem is, that you get a new Hibernate-Session, so you have to re-attach
> the objects if you re-use them.
>
> Cheers,
> Markus
>
>
> > ----- Original Message -----
> > From: "Juan Esteban Maya" <[EMAIL PROTECTED]>
> > To: "Tapestry users" <[email protected]>; "pepone pepone"
> > <[EMAIL PROTECTED]>
> > Sent: Tuesday, May 17, 2005 1:00 PM
> > Subject: Hibernate + Spring: LazyInitializationException
> >
> >
> > > Hi..
> > > I have been trying to use Tapestry with Spring + Hibernate 3.
> > > I have follow the wiki help about this issue, but i keep getting a
> > > LazyInitializationException everytime i load a lazy relation. Is there
> > > anything more needed to get hibernate lazy loading working?
> > >
> > > Thanks in advance
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> >
> > This message contains information that may be privileged or confidential and
> > is the property of the Capgemini Group. It is intended only for the person
> > to
> > whom it is addressed. If you are not the intended recipient, you are not
> > authorized to read, print, retain, copy, disseminate, distribute, or use
> > this message or any part thereof. If you receive this message in error,
> > please notify the sender immediately and delete all copies of this message.
This message contains information that may be privileged or confidential and is
the property of the Capgemini Group. It is intended only for the person to whom
it is addressed. If you are not the intended recipient, you are not authorized
to read, print, retain, copy, disseminate, distribute, or use this message or
any part thereof. If you receive this message in error, please notify the
sender immediately and delete all copies of this message.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]