|
From: <jue...@we...> - 2004-07-26 06:05:54
|
Colin, =20 I've just had a look at the new "defaultTemplateAllowCreateValue" flag = in HibernateDaoSupport, and I'm frankly not happy with it. We have a = special check whether the HibernateTemplate is self-created etc, = indicating - for me at least - that something is wrong there. I see your = use case, which is worth addressing, but I think the current approach is = not ideal. =20 This is not really how our XxxDaoSupport classes are meant to be used. = In the case of HibernateDaoSupport: either pass in a SessionFactory *or* = a preconfigured HibernateTemplate. If you want a default value for = HibernateTemplate's "allowCreate" flag, why not set up a = HibernateTemplate bean in your context, configure it with = "allowCreate"=3Dfalse and pass it to all your DAOs? This would work = nicely with the old HibernateDaoSupport implementation, without any = special checks... =20 My two main concerns are 1. consistency, i.e. that JdoDaoSupport and the = others would have to be coded in a similar fashion and 2. future = extensions, i.e. what happens if there's a further flag on = HibernateTemplate that you want to set via your DAO? Particularly in the = latter case, I'm not keen on having that sort of "if-self-created-then" = properties on the DAO: They confuse things, and just apply when passing = in a SessionFactory (not when passing in a HibernateTemplate), which is = not immediately obvious. =20 To allow for programmatic setting of such HibernateTemplate properties, = we could turn setSessionFactory non-final, allowing it to override with = a version that builds a custom HibernateTemplate for that = SessionFactory. That would be much cleaner, IMO, and easy to adapt in = JdoDaoSupport and co. Our data access templates and DAO base classes are = among the most popular parts of Spring, so it's important to indicate a = clear strategy there. =20 All things considered, I quite strongly believe that we should use to = the old HibernateDaoSupport implementation again, just turning = setSessionFactory non-final to allow for programmatic overriding. For = context-driven configuration, let's recommend to pass in a preconfigured = HibernateTemplate bean. Can I convince you of this? =20 Unfortunately, I'm already in a bit of a hurry here: I'd like to - = finally! - get 1.1 RC1 out tomorrow. =20 Juergen =20 ________________________________ Von: spr...@li... im Auftrag = von Colin Sampaleanu Gesendet: Do 15.07.2004 16:02 An: spr...@li... Betreff: Re: [Springframework-developer] HibernateDaoSupport I don't like that solution, because it will then also affect any HibernateTemplate that is passed in. The current code does not touch any template that is passed in. These changes do not want to modify that behaviour, but rather allow the default value for allowCreate on _new_ templates created to be specified. And I think there are two ways that people would want to play with the flag: either make their own subclass which sets the flag to false, and that becomes the superclass of all their DAOs, or alternately, do not use a subclass at all, but in some (or all) DAOs, specifically set the default value. Colin j=FCrgen h=F6ller [werk3AT] wrote: >Colin, > >What about simply invoking > > getHibernateTemplate().setAllowCreate(false); > >in the initDao implementation of your subclass? > >Juergen > > >________________________________ > >Von: spr...@li... im Auftrag = von Colin Sampaleanu >Gesendet: Do 15.07.2004 05:34 >An: spr...@li... >Betreff: [Springframework-developer] HibernateDaoSupport > > > >Juergen, > >The existing code in HibernateDaoSupport created a HibernateTemplate >with the allowCreate flag as true by default, and as the >setSessionFactory method where the template was created was final, = there >was no way to override this. I have created a protected field called >defaultTemplateAllowCreateValue (true by default to maintain existing >behaviour), which a user HibernateDaoSupport subclass may override. >Additionally, I have added a setter for this default value, so a DAO >instance can be set to true or false specifically (without having to >subclass). This value does not affect any HibernateTemplate passed in >explicitly. > >Colin >=20 > ------------------------------------------------------- This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools! Get your free copy of BEA WebLogic Workshop 8.1 today. http://ads.osdn.com/?ad_id=3D4721&alloc_id=3D10040&op=3Dclick _______________________________________________ Springframework-developer mailing list Spr...@li... https://lists.sourceforge.net/lists/listinfo/springframework-developer |