|
From: Misra, P. <pra...@fm...> - 2006-07-14 10:07:40
|
I face a problem while using Hibernate.
I do a search on owner names and get a list of owner id and names and
when I click on a particular owner it takes me to the view screen.
To view the details of owner, the method(code piece) which I use is -=20
session =3D
HibernateSessionFactory.getInstance().currentSession();
tx =3D session.beginTransaction();
TFmsOwnerInformation tOwner =3D new
TFmsOwnerInformation();
tOwner =3D (TFmsOwnerInformation) session.load(
TFmsOwnerInformation.class, new
Long(ownerId));
list.add(tOwner);
In the finally I do=20
finally {
if(tx !=3D null) tx.commit();
if (session !=3D null) session.close();
}
But If I do session.close() in finally I get an error saying:=20
15:12:44,199 ERROR [LazyInitializationException] could not initialize
proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy -
the owning Session was closed
To avoid this error I used session.flush(). But this created another
problem. I have a Update button on the view screen. After I click on
Update(the update screen loads the data by calling the same method) and
then save the data, I come back to the view screen. Hence the same
method is used for view and update screen to load. But it used to
display stale data in the view screen/update screen a lot of times.
To avoid this a method was added by us -
HibernateSessionFactory.closeHibernateFactory(); before session =3D
HibernateSessionFactory.getInstance().currentSession();
closeHibernateFactory() ::
public static synchronized void closeHibernateFactory() {
=09
s_instance =3D null;
Session s =3D (Session) s_session.get();
s =3D null;
s_session.set(s); =09
=09
}
But this method again instantiates all the mapping files. Can anybody
please give me a solution to this?
Thanks & Regards,=20
Pragyan
------------------------------------------------------------------------
-----------------
This e-mail, and any attachment hereto, is privileged, confidential and
proprietary information of Fidelity Business Services India Pvt. Ltd. or
any of the Fidelity Investments group companies and is intended for use
only by the individual or entity to whom it is addressed. If you are not
the intended recipient of this e-mail, or if you have otherwise received
this e-mail in error, please immediately notify the sender and
permanently delete the original mail, any print outs and any copies -
including the attachments. Any dissemination, distribution or copying of
this e-mail is strictly prohibited. All e-mails sent from or to Fidelity
Business Services India Pvt. Ltd. may be subject to our monitoring
procedures.
|