If you are using tapestry-hibernate, the injectable Session service is
a perthread proxy.  It can be shared across threads, but each method
invocation on the proxy is redirected to a real per-thread Hibernate
session.

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]
>
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to