My first ever web app was done using Tapestry and Hibernate. So what i did then wasn't the best way to go about it. But here it goes. I made a lot of static methods and in these methods i would obtain a Session object from a singleton SessionFactory, do some work and commit/close the session.
After finding about Hibernate properly and also getting to know more Tapestry, the obvious place to keep a Session is in the Visit object. And also to use the Transaction capability of Hibernate. For example, you have a banking website. when a person logs on, a Session is created in the Visit object and as the person does their banking from several pages, this is taken care of by opening and closing a new transaction for each think he/she does on your website. At the end, you commit and close the session. This way, if there are any exceptions, the transaction can be rolled back. With the use of Sessions in Hibernate, it seems they are good when you know exactly what will happen between opening and closing a session. it seems that when you don't know what will happen between them, then use the transactions to do the units of work. Also by keeping the Session in the Visit object, you keep all work logic at the level of Tapstry and not burried under a whole lot of database software. the merits of this? i don't know, if anyone does let me know! :-) But i too am looking fwd to other people's use of Tapestry/Hibernate and soo how they have done it. Hope this helps. Saqib --- Luke Galea <[EMAIL PROTECTED]> 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:everman@;precedadesign.com] > 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 http://careers.yahoo.com.au - Yahoo! Careers - 1,000's of jobs waiting online for you! ------------------------------------------------------- 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
