You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by esper <ma...@yahoo.com> on 2012/10/12 11:47:22 UTC

Tapestry & hibernate session - without tapestry-hibernate module

Hi good people,

i'm trying to get tapestry working with pure hibernate (no
tapestry-hibernate module involved).
With tapestry-hibernate you just inject a session into your components but
how does it work without the module? Where do I initialize my session
object? I don't want to do this heavy operation every time the component
gets called!

is there a good documentation on how to do this you can point me to?



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Tapestry-hibernate-session-without-tapestry-hibernate-module-tp5716838.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: Tapestry & hibernate session - without tapestry-hibernate module

Posted by Lance Java <la...@googlemail.com>.
https://git-wip-us.apache.org/repos/asf?p=tapestry-5.git;a=blob;f=tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/HibernateCoreModule.java



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Tapestry-hibernate-session-without-tapestry-hibernate-module-tp5716838p5716841.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: Tapestry & hibernate session - without tapestry-hibernate module

Posted by Lance Java <la...@googlemail.com>.
Download the source code for tapestry-hibernate and take a look at how it
works. The session will end up being a proxy to a per-thread value. If you
want two different db connections, you might want to consider giving each
session a marker annotation to differentiate them.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Tapestry-hibernate-session-without-tapestry-hibernate-module-tp5716838p5716840.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: Tapestry & hibernate session - without tapestry-hibernate module

Posted by esper <ma...@yahoo.com>.
One possible solution would be to create a HibernateUtils class for example
to hold a session object. I could then persist that object on application
state lavel like this:

class HibernateUtils {
...
@Persist(PersistenceConstants.SESSION)
private Session session = ...
...
}

is this a way to go? if it is, then how would I inject this object into
other components?



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Tapestry-hibernate-session-without-tapestry-hibernate-module-tp5716838p5716839.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: Tapestry & hibernate session - without tapestry-hibernate module

Posted by "Wechsung, Wulf" <wu...@sap.com>.
> Mr. Wulf (shit this sounds cool!)
:)

Well, the available T5 session scopes are singleton and per-thread. 
Singleton means that the service will be built only once and then shared for all threads and therefore requests. 
Per-thread means that the service will be built for every single request.

More details here under "Defining Service Scope":
http://tapestry.apache.org/defining-tapestry-ioc-services.html

Kind Regards,
Wulf


-----Original Message-----
From: esper [mailto:marin_mamic@yahoo.com] 
Sent: Freitag, 12. Oktober 2012 13:55
To: users@tapestry.apache.org
Subject: RE: Tapestry & hibernate session - without tapestry-hibernate module

Mr. Wulf (shit this sounds cool!)

i didn't even know this could be done! but there is a questions that comes
to mind:
can injected objects be built on demand (runtime) or is it only once per
application session? once per thread basically.

you see, there is a reason why I decided to remove tapestry-hibernate module
and the reason is I want to rebuild my session on demand.

sorry for not trying out your answer, Lance. I will eventually end up there
but as for now, with the limited knowledge I have, it's still too much to
swallow.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Tapestry-hibernate-session-without-tapestry-hibernate-module-tp5716838p5716844.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


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


RE: Tapestry & hibernate session - without tapestry-hibernate module

Posted by esper <ma...@yahoo.com>.
Mr. Wulf (shit this sounds cool!)

i didn't even know this could be done! but there is a questions that comes
to mind:
can injected objects be built on demand (runtime) or is it only once per
application session? once per thread basically.

you see, there is a reason why I decided to remove tapestry-hibernate module
and the reason is I want to rebuild my session on demand.

sorry for not trying out your answer, Lance. I will eventually end up there
but as for now, with the limited knowledge I have, it's still too much to
swallow.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Tapestry-hibernate-session-without-tapestry-hibernate-module-tp5716838p5716844.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: Tapestry & hibernate session - without tapestry-hibernate module

Posted by "Wechsung, Wulf" <wu...@sap.com>.
Hi,

The awesome thing is that everything in Tapestry can be a service! All you need is a service builder method and the @Inject annotation in your Services, Pages and Components. 

So for a hibernate session you could (not saying this is a good solution, but it's a start) a service builder method for Session in the application module like so:

@Scope(PER_THREAD) // means every thread will get it's own instance
public Session buildSession( @Inject PerThreadManager,  @Inject SessionFactory ){
      Session session = // setup session here;
  
      // clean up session at the end of request
      perthreadManager.addThreadCleanupListener(new ThreadCleanupListener() {

            @Override
            public void threadDidCleanup() {
                    session.close();
            }
        });
      return session;
}


For this to work you need to do the same thing for SessionFactory as well. 


In your Pages/Components/Services you can then simply write:

@Inject
private Session session;

I hope this illustrates the general principle.


Kind Regards,
Wulf

-----Original Message-----
From: esper [mailto:marin_mamic@yahoo.com] 
Sent: Freitag, 12. Oktober 2012 11:47
To: users@tapestry.apache.org
Subject: Tapestry & hibernate session - without tapestry-hibernate module

Hi good people,

i'm trying to get tapestry working with pure hibernate (no
tapestry-hibernate module involved).
With tapestry-hibernate you just inject a session into your components but
how does it work without the module? Where do I initialize my session
object? I don't want to do this heavy operation every time the component
gets called!

is there a good documentation on how to do this you can point me to?



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Tapestry-hibernate-session-without-tapestry-hibernate-module-tp5716838.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


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