You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by DH <ni...@gmail.com> on 2009/03/11 04:23:48 UTC

Re: T5ï¼s getting new Hibernate session in a lengthy thread

Maybe you can directly use HibernateSessionSource service instead of HibernateSessionManager.
HibernateSessionSource.create() creates a new session always, and do remember to commit and close the session by yourself.

Thanks,
DH


----- Original Message ----- 
From: "Angelo Chen" <an...@yahoo.com.hk>
To: <us...@tapestry.apache.org>
Sent: Wednesday, March 11, 2009 11:16 AM
Subject: T5ï¼s getting new Hibernate session in a lengthy thread


> 
> Hi,
> 
> I need to run a lengthy thread where some database update happens, is there
> a way to minimize the time when a Hibernate Session is used? something
> similar to:
> 
> do while not done
> 
> // do some processing here
> obtain a session
> use the session
> release the session
> 
> enddo
> 
> If I use HibernateSessionManager, it seems there is no way to release and
> obtain a new session, any idea?
> -- 
> View this message in context: http://www.nabble.com/T5%EF%BC%9A-getting-new-Hibernate-session-in-a-lengthy-thread-tp22448134p22448134.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
>

Re: T5ï¼s getting new Hibernate session in a lengthy thread

Posted by DH <ni...@gmail.com>.
Hi,

Yes, I think so. HibernateSessionSource is top of HibernateSessionManager.


DH


----- Original Message ----- 
From: "Angelo Chen" 
To: <us...@tapestry.apache.org>
Sent: Wednesday, March 11, 2009 2:08 PM
Subject: Re: T5ï¼s getting new Hibernate session in a lengthy thread



Hi,

HibernateSessionManagerImpl uses HibernateSessionSource to create a session,
if we use HibernateSessionSource service in code as suggested by you, then
seems ok, right?



dh ning wrote:
> 
> Sorry, my fault. If code don't call any method of HibernateSessionManager,
> it won't create a session.
> 
> Thanks,
> DH
> 
> 
> ----- Original Message ----- 
> From: "Angelo Chen" 
> To: <us...@tapestry.apache.org>
> Sent: Wednesday, March 11, 2009 1:55 PM
> Subject: Re: T5ï¼s getting new Hibernate session in a lengthy thread
> 
> 
> 
> that will be a thread trigger by Quartz, create the session, close the
> session repeat this until thread is over, i don't know any impact from
> Tapestry-Hibernate.
> 
> 
> dh ning wrote:
>> 
>> I haven't tried it yet because now my application is out of
>> tapestry-hibernate.
>> But from source code of tapestry-hibernate, it should be doable.
>> 
>> But I still doubt how you close the session created by
>> HibernateSessionManager (thread scope). 
>> If you don't close it manually, the session still last fro the whole
>> request process.
>> If close manually, maybe 'session has closed' exception is thrown by
>> tapestry-hibernate because at the end tapestry would try to close the
>> session of HibernateSessionManager, but it has been closed manually.
>> 
>> Thanks,
>> DH
>> 
>> 
>> ----- Original Message ----- 
>> From: "Angelo Chen" To: <us...@tapestry.apache.org>
>> Sent: Wednesday, March 11, 2009 1:17 PM
>> Subject: Re: T5ï¼s getting new Hibernate session in a lengthy thread
>> 
>> 
>> 
>> Hi DH,
>> 
>> That sounds doable, we will inject the HibernateSessionSource then call
>> create() to obtain the session?
>> 
>> Angelo
>> 
>> 
>> dh ning wrote:
>>> 
>>> Maybe you can directly use HibernateSessionSource service instead of
>>> HibernateSessionManager.
>>> HibernateSessionSource.create() creates a new session always, and do
>>> remember to commit and close the session by yourself.
>>> 
>>> Thanks,
>>> DH
>>> 
>>> 
>>> ----- Original Message ----- 
>>> From: "Angelo Chen" <an...@yahoo.com.hk>
>>> To: <us...@tapestry.apache.org>
>>> Sent: Wednesday, March 11, 2009 11:16 AM
>>> Subject: T5ï¼s getting new Hibernate session in a lengthy thread
>>> 
>>> 
>>>> 
>>>> Hi,
>>>> 
>>>> I need to run a lengthy thread where some database update happens, is
>>>> there
>>>> a way to minimize the time when a Hibernate Session is used? something
>>>> similar to:
>>>> 
>>>> do while not done
>>>> 
>>>> // do some processing here
>>>> obtain a session
>>>> use the session
>>>> release the session
>>>> 
>>>> enddo
>>>> 
>>>> If I use HibernateSessionManager, it seems there is no way to release
>>>> and
>>>> obtain a new session, any idea?
>>>> -- 
>>>> View this message in context:
>>>> http://www.nabble.com/T5%EF%BC%9A-getting-new-Hibernate-session-in-a-lengthy-thread-tp22448134p22448134.html
>>>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>> 
>>>>
>>> 
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/T5%EF%BC%9A-getting-new-Hibernate-session-in-a-lengthy-thread-tp22448134p22448992.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> 
>> 
>> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/T5%EF%BC%9A-getting-new-Hibernate-session-in-a-lengthy-thread-tp22448134p22449240.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%EF%BC%9A-getting-new-Hibernate-session-in-a-lengthy-thread-tp22448134p22449328.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5ï¼s getting new Hibernate session in a lengthy thread

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi,

HibernateSessionManagerImpl uses HibernateSessionSource to create a session,
if we use HibernateSessionSource service in code as suggested by you, then
seems ok, right?



dh ning wrote:
> 
> Sorry, my fault. If code don't call any method of HibernateSessionManager,
> it won't create a session.
> 
> Thanks,
> DH
> 
> 
> ----- Original Message ----- 
> From: "Angelo Chen" 
> To: <us...@tapestry.apache.org>
> Sent: Wednesday, March 11, 2009 1:55 PM
> Subject: Re: T5ï¼s getting new Hibernate session in a lengthy thread
> 
> 
> 
> that will be a thread trigger by Quartz, create the session, close the
> session repeat this until thread is over, i don't know any impact from
> Tapestry-Hibernate.
> 
> 
> dh ning wrote:
>> 
>> I haven't tried it yet because now my application is out of
>> tapestry-hibernate.
>> But from source code of tapestry-hibernate, it should be doable.
>> 
>> But I still doubt how you close the session created by
>> HibernateSessionManager (thread scope). 
>> If you don't close it manually, the session still last fro the whole
>> request process.
>> If close manually, maybe 'session has closed' exception is thrown by
>> tapestry-hibernate because at the end tapestry would try to close the
>> session of HibernateSessionManager, but it has been closed manually.
>> 
>> Thanks,
>> DH
>> 
>> 
>> ----- Original Message ----- 
>> From: "Angelo Chen" To: <us...@tapestry.apache.org>
>> Sent: Wednesday, March 11, 2009 1:17 PM
>> Subject: Re: T5ï¼s getting new Hibernate session in a lengthy thread
>> 
>> 
>> 
>> Hi DH,
>> 
>> That sounds doable, we will inject the HibernateSessionSource then call
>> create() to obtain the session?
>> 
>> Angelo
>> 
>> 
>> dh ning wrote:
>>> 
>>> Maybe you can directly use HibernateSessionSource service instead of
>>> HibernateSessionManager.
>>> HibernateSessionSource.create() creates a new session always, and do
>>> remember to commit and close the session by yourself.
>>> 
>>> Thanks,
>>> DH
>>> 
>>> 
>>> ----- Original Message ----- 
>>> From: "Angelo Chen" <an...@yahoo.com.hk>
>>> To: <us...@tapestry.apache.org>
>>> Sent: Wednesday, March 11, 2009 11:16 AM
>>> Subject: T5ï¼s getting new Hibernate session in a lengthy thread
>>> 
>>> 
>>>> 
>>>> Hi,
>>>> 
>>>> I need to run a lengthy thread where some database update happens, is
>>>> there
>>>> a way to minimize the time when a Hibernate Session is used? something
>>>> similar to:
>>>> 
>>>> do while not done
>>>> 
>>>> // do some processing here
>>>> obtain a session
>>>> use the session
>>>> release the session
>>>> 
>>>> enddo
>>>> 
>>>> If I use HibernateSessionManager, it seems there is no way to release
>>>> and
>>>> obtain a new session, any idea?
>>>> -- 
>>>> View this message in context:
>>>> http://www.nabble.com/T5%EF%BC%9A-getting-new-Hibernate-session-in-a-lengthy-thread-tp22448134p22448134.html
>>>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>> 
>>>>
>>> 
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/T5%EF%BC%9A-getting-new-Hibernate-session-in-a-lengthy-thread-tp22448134p22448992.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> 
>> 
>> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/T5%EF%BC%9A-getting-new-Hibernate-session-in-a-lengthy-thread-tp22448134p22449240.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%EF%BC%9A-getting-new-Hibernate-session-in-a-lengthy-thread-tp22448134p22449328.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5ï¼s getting new Hibernate session in a lengthy thread

Posted by DH <ni...@gmail.com>.
Sorry, my fault. If code don't call any method of HibernateSessionManager, it won't create a session.

Thanks,
DH


----- Original Message ----- 
From: "Angelo Chen" 
To: <us...@tapestry.apache.org>
Sent: Wednesday, March 11, 2009 1:55 PM
Subject: Re: T5ï¼s getting new Hibernate session in a lengthy thread



that will be a thread trigger by Quartz, create the session, close the
session repeat this until thread is over, i don't know any impact from
Tapestry-Hibernate.


dh ning wrote:
> 
> I haven't tried it yet because now my application is out of
> tapestry-hibernate.
> But from source code of tapestry-hibernate, it should be doable.
> 
> But I still doubt how you close the session created by
> HibernateSessionManager (thread scope). 
> If you don't close it manually, the session still last fro the whole
> request process.
> If close manually, maybe 'session has closed' exception is thrown by
> tapestry-hibernate because at the end tapestry would try to close the
> session of HibernateSessionManager, but it has been closed manually.
> 
> Thanks,
> DH
> 
> 
> ----- Original Message ----- 
> From: "Angelo Chen" To: <us...@tapestry.apache.org>
> Sent: Wednesday, March 11, 2009 1:17 PM
> Subject: Re: T5ï¼s getting new Hibernate session in a lengthy thread
> 
> 
> 
> Hi DH,
> 
> That sounds doable, we will inject the HibernateSessionSource then call
> create() to obtain the session?
> 
> Angelo
> 
> 
> dh ning wrote:
>> 
>> Maybe you can directly use HibernateSessionSource service instead of
>> HibernateSessionManager.
>> HibernateSessionSource.create() creates a new session always, and do
>> remember to commit and close the session by yourself.
>> 
>> Thanks,
>> DH
>> 
>> 
>> ----- Original Message ----- 
>> From: "Angelo Chen" <an...@yahoo.com.hk>
>> To: <us...@tapestry.apache.org>
>> Sent: Wednesday, March 11, 2009 11:16 AM
>> Subject: T5ï¼s getting new Hibernate session in a lengthy thread
>> 
>> 
>>> 
>>> Hi,
>>> 
>>> I need to run a lengthy thread where some database update happens, is
>>> there
>>> a way to minimize the time when a Hibernate Session is used? something
>>> similar to:
>>> 
>>> do while not done
>>> 
>>> // do some processing here
>>> obtain a session
>>> use the session
>>> release the session
>>> 
>>> enddo
>>> 
>>> If I use HibernateSessionManager, it seems there is no way to release
>>> and
>>> obtain a new session, any idea?
>>> -- 
>>> View this message in context:
>>> http://www.nabble.com/T5%EF%BC%9A-getting-new-Hibernate-session-in-a-lengthy-thread-tp22448134p22448134.html
>>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>> 
>>>
>> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/T5%EF%BC%9A-getting-new-Hibernate-session-in-a-lengthy-thread-tp22448134p22448992.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%EF%BC%9A-getting-new-Hibernate-session-in-a-lengthy-thread-tp22448134p22449240.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5ï¼s getting new Hibernate session in a lengthy thread

Posted by Angelo Chen <an...@yahoo.com.hk>.
that will be a thread trigger by Quartz, create the session, close the
session repeat this until thread is over, i don't know any impact from
Tapestry-Hibernate.


dh ning wrote:
> 
> I haven't tried it yet because now my application is out of
> tapestry-hibernate.
> But from source code of tapestry-hibernate, it should be doable.
> 
> But I still doubt how you close the session created by
> HibernateSessionManager (thread scope). 
> If you don't close it manually, the session still last fro the whole
> request process.
> If close manually, maybe 'session has closed' exception is thrown by
> tapestry-hibernate because at the end tapestry would try to close the
> session of HibernateSessionManager, but it has been closed manually.
> 
> Thanks,
> DH
> 
> 
> ----- Original Message ----- 
> From: "Angelo Chen" To: <us...@tapestry.apache.org>
> Sent: Wednesday, March 11, 2009 1:17 PM
> Subject: Re: T5ï¼s getting new Hibernate session in a lengthy thread
> 
> 
> 
> Hi DH,
> 
> That sounds doable, we will inject the HibernateSessionSource then call
> create() to obtain the session?
> 
> Angelo
> 
> 
> dh ning wrote:
>> 
>> Maybe you can directly use HibernateSessionSource service instead of
>> HibernateSessionManager.
>> HibernateSessionSource.create() creates a new session always, and do
>> remember to commit and close the session by yourself.
>> 
>> Thanks,
>> DH
>> 
>> 
>> ----- Original Message ----- 
>> From: "Angelo Chen" <an...@yahoo.com.hk>
>> To: <us...@tapestry.apache.org>
>> Sent: Wednesday, March 11, 2009 11:16 AM
>> Subject: T5ï¼s getting new Hibernate session in a lengthy thread
>> 
>> 
>>> 
>>> Hi,
>>> 
>>> I need to run a lengthy thread where some database update happens, is
>>> there
>>> a way to minimize the time when a Hibernate Session is used? something
>>> similar to:
>>> 
>>> do while not done
>>> 
>>> // do some processing here
>>> obtain a session
>>> use the session
>>> release the session
>>> 
>>> enddo
>>> 
>>> If I use HibernateSessionManager, it seems there is no way to release
>>> and
>>> obtain a new session, any idea?
>>> -- 
>>> View this message in context:
>>> http://www.nabble.com/T5%EF%BC%9A-getting-new-Hibernate-session-in-a-lengthy-thread-tp22448134p22448134.html
>>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>> 
>>>
>> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/T5%EF%BC%9A-getting-new-Hibernate-session-in-a-lengthy-thread-tp22448134p22448992.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%EF%BC%9A-getting-new-Hibernate-session-in-a-lengthy-thread-tp22448134p22449240.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5ï¼s getting new Hibernate session in a lengthy thread

Posted by DH <ni...@gmail.com>.
I haven't tried it yet because now my application is out of tapestry-hibernate.
But from source code of tapestry-hibernate, it should be doable.

But I still doubt how you close the session created by HibernateSessionManager (thread scope). 
If you don't close it manually, the session still last fro the whole request process.
If close manually, maybe 'session has closed' exception is thrown by tapestry-hibernate because at the end tapestry would try to close the session of HibernateSessionManager, but it has been closed manually.

Thanks,
DH


----- Original Message ----- 
From: "Angelo Chen" To: <us...@tapestry.apache.org>
Sent: Wednesday, March 11, 2009 1:17 PM
Subject: Re: T5ï¼s getting new Hibernate session in a lengthy thread



Hi DH,

That sounds doable, we will inject the HibernateSessionSource then call
create() to obtain the session?

Angelo


dh ning wrote:
> 
> Maybe you can directly use HibernateSessionSource service instead of
> HibernateSessionManager.
> HibernateSessionSource.create() creates a new session always, and do
> remember to commit and close the session by yourself.
> 
> Thanks,
> DH
> 
> 
> ----- Original Message ----- 
> From: "Angelo Chen" <an...@yahoo.com.hk>
> To: <us...@tapestry.apache.org>
> Sent: Wednesday, March 11, 2009 11:16 AM
> Subject: T5ï¼s getting new Hibernate session in a lengthy thread
> 
> 
>> 
>> Hi,
>> 
>> I need to run a lengthy thread where some database update happens, is
>> there
>> a way to minimize the time when a Hibernate Session is used? something
>> similar to:
>> 
>> do while not done
>> 
>> // do some processing here
>> obtain a session
>> use the session
>> release the session
>> 
>> enddo
>> 
>> If I use HibernateSessionManager, it seems there is no way to release and
>> obtain a new session, any idea?
>> -- 
>> View this message in context:
>> http://www.nabble.com/T5%EF%BC%9A-getting-new-Hibernate-session-in-a-lengthy-thread-tp22448134p22448134.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> 
>>
> 

-- 
View this message in context: http://www.nabble.com/T5%EF%BC%9A-getting-new-Hibernate-session-in-a-lengthy-thread-tp22448134p22448992.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5ï¼s getting new Hibernate session in a lengthy thread

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi DH,

That sounds doable, we will inject the HibernateSessionSource then call
create() to obtain the session?

Angelo


dh ning wrote:
> 
> Maybe you can directly use HibernateSessionSource service instead of
> HibernateSessionManager.
> HibernateSessionSource.create() creates a new session always, and do
> remember to commit and close the session by yourself.
> 
> Thanks,
> DH
> 
> 
> ----- Original Message ----- 
> From: "Angelo Chen" <an...@yahoo.com.hk>
> To: <us...@tapestry.apache.org>
> Sent: Wednesday, March 11, 2009 11:16 AM
> Subject: T5ï¼s getting new Hibernate session in a lengthy thread
> 
> 
>> 
>> Hi,
>> 
>> I need to run a lengthy thread where some database update happens, is
>> there
>> a way to minimize the time when a Hibernate Session is used? something
>> similar to:
>> 
>> do while not done
>> 
>> // do some processing here
>> obtain a session
>> use the session
>> release the session
>> 
>> enddo
>> 
>> If I use HibernateSessionManager, it seems there is no way to release and
>> obtain a new session, any idea?
>> -- 
>> View this message in context:
>> http://www.nabble.com/T5%EF%BC%9A-getting-new-Hibernate-session-in-a-lengthy-thread-tp22448134p22448134.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> 
>>
> 

-- 
View this message in context: http://www.nabble.com/T5%EF%BC%9A-getting-new-Hibernate-session-in-a-lengthy-thread-tp22448134p22448992.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org