You don't have to create an engine for this, you can use a WebRequestFilter (or whatever it's called).
-----Original Message----- From: Tony Herstell [mailto:[EMAIL PROTECTED] Sent: Friday, March 10, 2006 10:55 AM To: 'Tapestry users' Subject: Transaaction-Session-Per-Request BaseEngine Extension HowTo/Example??? This must be a very common question... Fodder for the FAQ or "Tapestry Almanac"? Moved my persistence over to Hibernate and as you expect this was a godsend and only took a couple of hours. Naturally, 2 weeks later I am still trying to get it to work ;) I have managed to get it to work pretty well by switching cascade off everywhere (probably due to exposing such a big object graph into the pages). Leaving me with a problem of transactions... The best solution reported on the internet (hibernate site) was to extend the BaseEngine and wrap all calls in a transaction. The solution below was pretty naive and I was wondering if someone has a better solution as the Visit object seems to not be available at this point (I am not using Spring yet). public class SentinelEngine extends BaseEngine { private static final long serialVersionUID = 7768775316660511012L; protected void setupForRequest(RequestContext context) { super.setupForRequest(context); // Start a session and a transaction System.out.println("Building up the session and and starting a transaction"); IDAOFactory datastore = AbstractDAOFactory.soleInstance(); datastore.getController().start(); Transaction transaction = (Transaction)datastore.getController().beginTrasnsaction(); Visit visit = (Visit)getVisit(); if (visit == null) { visit = new Visit(); } visit.setTransaction(transaction); setVisit(visit); } protected void cleanupAfterRequest(IRequestCycle cycle) { super.cleanupAfterRequest(cycle); // Commit the transaction and clear down the session System.out.println("committing the transaction and tearing down the session"); IDAOFactory datastore = AbstractDAOFactory.soleInstance(); Visit visit = (Visit)getVisit(); datastore.getController().commit(visit.getTransaction()); datastore.getController().finish(); visit.setTransaction(null); } } public class HibernateController implements IController { public void start() { SessionFactory.currentSession(); } public Object getSession() { Session session = SessionFactory.currentSession(); return session; } public Object beginTrasnsaction() { Session session = SessionFactory.currentSession(); return session.beginTransaction(); } public void commit(Object transaction) { ((Transaction)transaction).commit(); } public void finish() { Session session = SessionFactory.currentSession(); session.flush(); SessionFactory.closeSession(); } } -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.375 / Virus Database: 268.2.1/278 - Release Date: 9/03/2006 --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]