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.  [ 7 posts ] 
Author Message
 Post subject: When does hibernate detatch persistent objects from session
PostPosted: Mon Jul 21, 2008 3:29 am 
Newbie

Joined: Mon Jul 21, 2008 3:13 am
Posts: 3
Hi,
I would like to know when hibernate detaches persistent objects from session. Is it :
- session.clear()
- session.close()
- session.flush()

I am facing a problem where objects are still attached to the hibernate session even after a session.close(). The same behavior is also observed even if i set the hibernate.transaction.flush_before_completion to true.

FYI .. the transaction factory used in my application is the default JDBCTransactionFactory.

Following is my code snippet.

Code:
Transaction tx = session.beginTransaction();
xxx.....
session.save(transientObject);
tx.commit();
session.close()


Help would be greatly appreciated.

Regards,
Himadri


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 21, 2008 6:49 am 
Beginner
Beginner

Joined: Wed Sep 21, 2005 8:18 am
Posts: 31
objects are detached when session.clear or session.close() is called or when objects are written to any stream.

How did u know that objects are still attached even if session.close() is called?

_________________
amer sohail


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 21, 2008 7:27 am 
Newbie

Joined: Mon Jul 21, 2008 3:13 am
Posts: 3
I profiled my application and observed the same.
Any clues on whether the transactionmanager and anything else that might cause the issue.

Forgot to mention something- our application is using the Hibernate Connection pool. Is this causing an issue. I know that Hibernate connection pool is not recommended, but i would like to solve this problem before proceeding with configuration change in my application.

Thanks
Himadri


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 21, 2008 7:33 am 
Beginner
Beginner

Joined: Wed Sep 21, 2005 8:18 am
Posts: 31
Well i don't think so that objects are still attached with same session. Do one thing to confirm it:

After closing session, create new object and assign it same id as of saved object. Then open a session and save this new object. If you recieve error "a different object with same identifier already exists", then you are right otherwise don't worry everything is ok and objects are attached.

_________________
amer sohail


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 21, 2008 7:37 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Are you using openSession or getSession?

Once that Hibernate Session is closed, then the objects are detached, and I've never seen them reattach themselves. Something strange is going on.

Check out this tutorial on How Hibernate Works. It might give you a bit more insight on what's going on:

http://www.hiberbook.com/HiberBookWeb/learn.jsp?tutorial=07howhibernateworks

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 21, 2008 7:56 am 
Newbie

Joined: Mon Jul 21, 2008 3:13 am
Posts: 3
I am using factory.openSession()


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 25, 2008 4:46 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Do you have a compelling reason to use openSession over getSession? Are you aware of the differences?

If a serious decisions wasn't made behind the use of openSession, you will probably avoid some of these issues by using getSession.

Give it a try.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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