Jon - this looks great. I'm assuming this works great when calling DAOs or Hibernate persistence classes directly from the web tier. If I have the following layers
web (action classes) service (business logic) persistence (daos) And I'd like to use JUnit/Cactus to test them all. If I use your filter, I'm guessing I'll have to pass the Session object all the way down to the persistence layer? What is the recommended way to do this. Furthermore, if I architect my app in this way, for my test cases, should I obtain a session in the TestCase and then pass that in to my methods? All suggestions/recommendations welcome. You can see my example app (and how I'd doing it now) by downloading my struts-resume application from (http://www.raibledesigns.com/downloads). I'd like to figure out the best way to do this, as this struts-resume app is going to end up in a book, and I'm assuming some folks might use it as an example to architect there apps. Thanks, Matt > Hi All, > > I said in an email last week that I would post an example of how to use > Hibernate from a ServletFilter. > > Hopefully this example works because I copied and pasted it together from > the real one we are removing to remove some of the other dependencies that > we have. If somone finds a problem with it, let me know, and I'll try to > help you with it. > > I am attaching 3 files to this email: > > HibernateFilter.java - The source code for the ServletFilter > SessionProxy - A proxy object that looks like a Hibernate session so that > the session can be initialized when first used. > web.xml - An example web.xml file that shows you how to configure the > HibernateFilter > > The ServletFilter assumes that you are initializing the Hibernate datastore > somewhere else, you could also modify the init() method of the > HibernateFilter to initialize the datastore and session factories if you > wanted. (That is actually what I do, but I removed that part to simplify > the example.) On each request it will create a HibernateSession (or a proxy > that looks like a session) and store it in a request attribute. At the end > of the request, it will close it for you (in the case you use a proxy > object, it will close the session only if you initialized the session.) > > Jon... ------------------------------------------------------- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.com _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel