RE: Hibernate

Eric Everman <[email protected]>
Newsgroups gmane.comp.java.tapestry.devel
Message-ID <[email protected]>
Its true that you may share a session b/t multiple client requests, 
however, a session is *not* thread safe.  Thus, you will need to ensure 
that during updates only one client has access to it at a time.

Actually, I like your idea of keeping a Session in the RequestCycle.  Any 
component that needs a session could grab it from the RC.  One way to do 
this would be to create a base component that has a getSession() 
method.  Calling getSession() would retrieve an existing Session from the 
RC, or if none is found, create a Session and store it in the RC.  This 
component could also automatically add itself as a pageDetach listener for 
the page it is rendered on - when the page detaches, the component could 
grab the Session and flush / commit any transactions.

Sessions are supposed to be lightweight, so creating and disposing one for 
each request for which one is required shouldn't be a problem.

My earlier strategy of keeping one session for each client and detaching it 
when not in use would be more applicable to a situation where a users 
action spanned multiple requests before it was committed to the db (for 
instance a multi-page form that only get stored if it is complete).

More ideas welcome. . .

ee

At 11/13/2002, you wrote:
>I had figured that I would just use a singleton to store the
>SessionFactory. That seems to be working so far.
>
>The very end of the hibernate docs say: "When using a servlet only, you
>may reuse the same session for multiple client requests. Just remember
>to disconnect the session before returning control to the client."
>
>That leaves me to believe there is some reason not to hold open a
>session for an entire Visit... What do you think of just placing it in
>the request cycle? Then somewhere putting something to close it before
>completing the render of the entire page.. not sure how to accomplish
>this.. just an idea.
>
>Has anyone else had success?
>
>Luke Galea
>Software Development
>BlueCat Networks
>905-762-5225
>
>
>-----Original Message-----
>From: Eric Everman [mailto:[email protected]]
>Sent: November 12, 2002 7:01 PM
>To: Luke Galea; Tapestry Developer
>Subject: Re: [Tapestry-developer] Hibernate
>
>Hi Luke-
>
>I'm new to Tapestry, but have been using Hibernate for a while, so your
>questions struck a chord with me.  I am planning a Hibernate / Tapestry
>demo project, just so I can try combining the two.
>
>My current thinking for accessing the SessionFactory is to place it in
>the
>servlet application context at startup via a custom Tapestry
>Servlet.  Hibernate sessions would be created as needed for each client
>and
>stored in their Visit object.  Sessions are light weight, serializable,
>and
>'detachable' from the database, so I'm planning on allowing a client to
>keep the same session until their Visit is GC'ed.
>
>Each action on the part of the client involving Hibernate would then
>access
>the new or existing session, re-attach it to the db, *do stuff*, flush
>to
>db, then detach.
>
>Out of all of this, the part that seems most cumbersome is the need to
>access the servlet context for a global variable - it really seems like
>Tapestry should provide easier access to application level variables.
>
>Cheers,
>
>Eric Everman
>
>
>At 11/12/2002, Luke Galea wrote:
>
> >Hello..
> >
> >We are using Hibernate for our project.. and I am looking at using the
> >contrib Table component with Hibernate. As I know I am not the first to
>
> >use Tapestry with Hibernate I have a few questions.
> >
> >
> >    * Has anyone implemented a Hibernate-centric version of the Table
> > Model? Is there interest in such a thing being developed and added to
>the
> > contrib?
> >    * Where is the best place to store the Hibernate session so it can
>be
> > used through the request.. should it be place in the request cycle?
>How
> > should I ensure that it is closed before the cycle completes?
>
>
>
>-------------------------------------------------------
>This sf.net email is sponsored by: Are you worried about
>your web server security? Click here for a FREE Thawte
>Apache SSL Guide and answer your Apache SSL security
>needs: http://www.gothawte.com/rd523.html
>_______________________________________________
>Tapestry-developer mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/tapestry-developer



-------------------------------------------------------
This sf.net email is sponsored by: Are you worried about 
your web server security? Click here for a FREE Thawte 
Apache SSL Guide and answer your Apache SSL security 
needs: http://www.gothawte.com/rd523.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.