>
> How can I get the current (per-thread) hibernate-session (as configured
> through tapestry-hibernate) from a singleton custom tapestry service?
>

I haven't tried creating a getInstance type method for my service classes,
but here is my understanding. The default scope for a service is singleton.
When your service is auto built by Tapestry the parameters to the
constructor are proxies to the actual implementation. When your singleton
service has a dependancy on a perthread service the proxy gives you the
correct object for the current thread. For instance, all of my DAO classes
are registered as a service receiving the Session. Sessions are opened and
closed with the request, so if you're trying to access it outside of the
request you'd be in trouble.

Josh

On Wed, Jul 9, 2008 at 9:27 AM, Britske <[EMAIL PROTECTED]> wrote:

>
> I found some partial references on the list, but nothing that really
> answered
> the question, so:
> How can I get the current (per-thread) hibernate-session (as configured
> through tapestry-hibernate) from a singleton custom tapestry service?
>
> For reference:
> I have a MySingleton-class build as a tapestry service.
> MySingleton.getSingleton().getCurrentSession() should give me the current
> session (thread-bound) as managed by tapestry-hibernate.
> This would enable me to access the current session from any class (not just
> components or tapestry services)
>
>
> I tried 3 methods, 2 of which don't work, and 1 I'm not certain
>
> Method 1:
> build the MySingleton-class and inject Session at constructortime.
>
> Problem:  the hibernate session that is created on constructor-time stays
> assoaciated with MySingleton  (correct?). So this doesn't give a
> session-per-thread.
>
>
> Method 2:
> build the MySingleton-class and inject HibernateSessionSource
> getCurrentSession(){
>   return hibernateSessionSource.getSessionFactory().getCurrentSession();
> }
>
> Problem:
>
> but this gives error:
> org.hibernate.HibernateException: No CurrentSessionContext configured!
> I think this happens because the way the session is accessed bypasses the
> tapestry-hibernate session-in-view filter (HibernateSessionManager) which
> takes care of providing the context.
>
> Is there any way to make getSessionFactory() aware of the
> HibernateSessionManager? So the above works?
>
>
> Method 3:
> build the MySingleton-class and inject ProperyShadowBuilder  and
> HibernateSessionManager
>
> I figured this calling hibernateSessionManager.getSession() would give me
> the needed context (which lacked from method 2) . The problem is that
> HibernateSessionManager is not a singleton either.
> I thought this could be bypassed by doing :
>
> getCurrentSession(){
> return shadowBuilder.build(hibernateSessionManager, "session",
> Session.class);
> }
>
> However this still doens't ensure (I think) that hibernateSessionManager
> belongs to the current thread.
>
>
> Can anyone shed some light on this? I would highly appreciate it!
> Cheers,
> britske
>
>
> --
> View this message in context:
> http://www.nabble.com/T5%3A-getting-current-hibernate-session-%28per-thread%29-from-singleton-service-tp18365296p18365296.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


-- 
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.

Reply via email to