-->
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.  [ 9 posts ] 
Author Message
 Post subject: One session for the whole application
PostPosted: Sat Jul 30, 2005 5:35 am 
Newbie

Joined: Sat Jul 30, 2005 5:18 am
Posts: 6
I have a fat client and I'm using one session for the whole application. I disconnect the session when I'm done with it. However, any time there is an exception or if I wanna do something with a new thread. It creates another sessions by itself and then I get the error that says the object is associated under more then one session.
How can I avoid these? Thanks...


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 30, 2005 11:18 am 
Senior
Senior

Joined: Thu May 12, 2005 11:40 pm
Posts: 125
Location: Canada
As far as I know, Hibernate doesn't open sessions all by itself. Make sure you're closing the exceptional one properly.


Top
 Profile  
 
 Post subject: Re: One session for the whole application
PostPosted: Sat Jul 30, 2005 12:56 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
jamesh wrote:
I have a fat client and I'm using one session for the whole application. I disconnect the session when I'm done with it. However, any time there is an exception or if I wanna do something with a new thread. It creates another sessions by itself and then I get the error that says the object is associated under more then one session.
How can I avoid these? Thanks...


Read section 12.1.4 in the latest docs. It specifically says that you need to close your session if you get an exception.

As for the new session per thread, if you're using the ThreadLocal pattern for sessions described in Hibernate In Action, it will open a new session for each Thread.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 30, 2005 7:02 pm 
Regular
Regular

Joined: Wed May 11, 2005 11:57 pm
Posts: 80
Quote:
As for the new session per thread, if you're using the ThreadLocal pattern for sessions described in Hibernate In Action, it will open a new session for each Thread.


I believe the original poster mentioned that this is a fat client. If that's the case, then there is probably not a new thread for each request, or even a 'request' at all, which means that the ThreadLocal pattern will give you one thread for the whole application. This is an issue that I'm still trying to find an elegant solution for.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 30, 2005 7:05 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
jbarnum wrote:
Quote:
As for the new session per thread, if you're using the ThreadLocal pattern for sessions described in Hibernate In Action, it will open a new session for each Thread.


I believe the original poster mentioned that this is a fat client. If that's the case, then there is probably not a new thread for each request, or even a 'request' at all, which means that the ThreadLocal pattern will give you one thread for the whole application. This is an issue that I'm still trying to find an elegant solution for.


I was responding to this specific statement in the original post -

"However, any time there is an exception or if I wanna do something with a new thread. "

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject: Re: One session for the whole application
PostPosted: Mon Aug 01, 2005 10:04 am 
Newbie

Joined: Sat Jul 30, 2005 5:18 am
Posts: 6
[quote="pksiv"][quote="jamesh"]I have a fat client and I'm using one session for the whole application. I disconnect the session when I'm done with it. However, any time there is an exception or if I wanna do something with a new thread. It creates another sessions by itself and then I get the error that says the object is associated under more then one session.
How can I avoid these? Thanks...[/quote]

Read section 12.1.4 in the latest docs. It specifically says that you need to close your session if you get an exception.

As for the new session per thread, if you're using the ThreadLocal pattern for sessions described in Hibernate In Action, it will open a new session for each Thread.[/quote]

Yes I'm using ThreadLocal pattern. and I read that part too. I guess now my question is should I still use one session for the whole application or should I switch to session per request?

Thanks


Top
 Profile  
 
 Post subject: Re: One session for the whole application
PostPosted: Mon Aug 01, 2005 10:21 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
jamesh wrote:
pksiv wrote:
jamesh wrote:
I have a fat client and I'm using one session for the whole application. I disconnect the session when I'm done with it. However, any time there is an exception or if I wanna do something with a new thread. It creates another sessions by itself and then I get the error that says the object is associated under more then one session.
How can I avoid these? Thanks...


Read section 12.1.4 in the latest docs. It specifically says that you need to close your session if you get an exception.

As for the new session per thread, if you're using the ThreadLocal pattern for sessions described in Hibernate In Action, it will open a new session for each Thread.


Yes I'm using ThreadLocal pattern. and I read that part too. I guess now my question is should I still use one session for the whole application or should I switch to session per request?

Thanks


I've read many posts about this on here and while I think it might be okay to use 1 session for the whole application, everything I've read is that a Session is very lightweight and meant to be created many times so I don't think you'd have a problem with this approach.

You can read section 12.3.2 for more information on Long running sessions. Specifially, it talks about disconnecting from the JDBC connection when your waiting on the user so you don't tie up the connections during user think time.

I work with mostly webapps so the One Session-per-request works best for me. But I actually think this approach simplifies things in all cases.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject: Re: One session for the whole application
PostPosted: Mon Aug 01, 2005 10:47 am 
Newbie

Joined: Sat Jul 30, 2005 5:18 am
Posts: 6
[quote="pksiv"][quote="jamesh"][quote="pksiv"][quote="jamesh"]I have a fat client and I'm using one session for the whole application. I disconnect the session when I'm done with it. However, any time there is an exception or if I wanna do something with a new thread. It creates another sessions by itself and then I get the error that says the object is associated under more then one session.
How can I avoid these? Thanks...[/quote]

Read section 12.1.4 in the latest docs. It specifically says that you need to close your session if you get an exception.

As for the new session per thread, if you're using the ThreadLocal pattern for sessions described in Hibernate In Action, it will open a new session for each Thread.[/quote]

Yes I'm using ThreadLocal pattern. and I read that part too. I guess now my question is should I still use one session for the whole application or should I switch to session per request?

Thanks[/quote]

I've read many posts about this on here and while I think it might be okay to use 1 session for the whole application, everything I've read is that a Session is very lightweight and meant to be created many times so I don't think you'd have a problem with this approach.

You can read section 12.3.2 for more information on Long running sessions. Specifially, it talks about disconnecting from the JDBC connection when your waiting on the user so you don't tie up the connections during user think time.

I work with mostly webapps so the One Session-per-request works best for me. But I actually think this approach simplifies things in all cases.[/quote]

[b]Thanks for your reply!
The problem is the application came a long way and I just checked to see how much change it needs to switch to session-per-request and it looks like a nightmare...I wish there was more Hibernate documentation for fat client/client server applications and Long session problems.[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 11:55 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Session is not thread safe, proxies for your object are not thread safe too (this is true for any client including "fat" ). Use session per thread and reload data too, if you use single session for optimization only (cache) then session factory level cache must help too.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.