-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate session issue
PostPosted: Fri Jul 14, 2006 6:41 am 
Newbie

Joined: Fri Jul 14, 2006 6:33 am
Posts: 1
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 -

session = HibernateSessionFactory.getInstance().currentSession();
tx = session.beginTransaction();
TFmsOwnerInformation tOwner = new TFmsOwnerInformation();
tOwner = (TFmsOwnerInformation) session.load(
TFmsOwnerInformation.class, new Long(ownerId));
list.add(tOwner);

In the finally I do
finally {
if(tx != null) tx.commit();
if (session != null) session.close();
}

But If I do session.close() in finally I get an error saying:
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 = HibernateSessionFactory.getInstance().currentSession();
closeHibernateFactory() ::

public static synchronized void closeHibernateFactory() {

s_instance = null;
Session s = (Session) s_session.get();
s = null;
s_session.set(s);

}

But this method again instantiates all the mapping files. Can anybody please give me a solution to this?


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

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.