Wow I love that. Somehow I mistakenly thought it didn't work that way,
thanks. 
 
As a related question :
is there a way to get the 'real' session instead of the proxy on a call to 
getSession()

The reason I'm asking is that in a lot of cases I want to use (Hibernate's)
DetachedCriteria's, so I can make a criteria, pass that as a parameter to a
repository and let the repository get the current session and create a real
criteria. (For reasons of seperation)

This is done through detachedCriteria.getExecutableCriteria(getSession());

However this always gives a classCastException, like: 
java.lang.ClassCastException: $Session_11b08fbaf1e cannot be cast to
org.hibernate.engine.SessionImplementor.

for a related post (similar problem) see:
http://www.nabble.com/Hivemind-creates-proxy-Hibernate-Session-td9845916.html

Therefore I need the 'real' object. 
diong getSession().getSessionFactory().getCurrentSession() would solve my
problem, since that would be both the session of the current thread and the
real object, but (as described in method 2 of my post) the context assigned
to be tapestry-hibernate isn't there when accessing the session in this way.

Any suggestions on how to solve this as well? Much apreciated!






Howard Lewis Ship wrote:
> 
> 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]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/T5%3A-getting-current-hibernate-session-%28per-thread%29-from-singleton-service-tp18365296p18367496.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]

Reply via email to