|
From: Cameron B. <ca...@da...> - 2003-10-27 16:18:09
|
Thanks for y our prompt reply. Yeah, that all makes sense. In regards to mapping for an abstract class - is it possible to specify a mapping that gets inherited automatically, based on the class hierarchy i.e. Map the HibernateDaoSupport.sessionFactory property to name "mySessionFactory", and then any class that extends HibernateDaoSupport inherit that mapping ? Thanks again. Cameron. Colin Sampaleanu wrote: > Cameron Braid wrote: > >> I am just beginning to use the Spring framework, and so far I am very >> impressed. >> >> One thing that I don't quite understand is the mandatory requirement >> for each DAO and BO (Business Object) to support the >> set/getSessionFactory method. >> >> The reason that I say it is mandatory is because the only way to >> obtain the current session (as far as I know) is to use >> SessionFactoryUtils.getSession(SessionFactory...). This means that >> each DAO/BO requires a setSessionFactory property to be able to be >> passed it from the spring container. This also requires that each >> DAO/BO to be configured to bind the SessionFactory instance within >> the applicationContext.xml >> >> What I would think would be a simple and quite common use case would >> be for an app to require only one session factory. Therefore I think >> that the SessionFactoryUtils, and related classes , could use a >> static field to store the 'default' session factory. >> >> Has something like this been considered ? >> Do you think that this is a good or a bad idea ? >> > Cameron, > > To clarify, your business objects would generally do not need to have > a setSessionFactory method. They would need setters for one or more > Mapper/DAO objects, and those Mapper/DAO objects would need the > setSessionFactory method. > > As for the idea of having the Mapper/DAO objects not need the session > factory parameter, and getting it from a singleton of some sort, that > approach would work for some use cases, but using a singleton like > this is just not very clean. It becomes harder to test code in > isolation, and usually locks you into the singleton approach. > > You are at most going to declare each mapper/dao once in the > application context. Giving it the session factory paramter is not a > big deal. In terms of the actual code in the mapper/dao to support > this, this can be provided by an abstract base class, and in fact > Spring has such a class (for Hibernate) called HibernateDaoSupport. > > Regards, > Colin > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: The SF.net Donation Program. > Do you like what SourceForge.net is doing for the Open > Source Community? Make a contribution, and help us add new > features and functionality. Click here: http://sourceforge.net/donate/ > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer |