DAOs and Hibernate and Spring and all that hullabaloo
Submitted by charlie.collins on Wed, 03/01/2006 - 23:44
Tagged:
The last few days I have been working on a new data access model for jPenguin. New opportunity to make this "all new code". So I went back and read through the Fowler IoC explanation, again, and frankly I still dont quite understand the frenzy (the pattern I get, the "dont call us we will call you" nature makes sense, the explosion of use and extreme popularity I do not quite understand).
Specifially what I dont get is why I need Spring or Pico, et al, to do this for me? In Fowlers explanation he says an "assembler" is needed to determine the dependency you want to "inject". In his words "populates a field in the lister class with an appropriate implementation for the finder interface". If you omit the words "lister" and "finder" from that sentence you have an overview of IoC (at least in my naive and admittedly strained understanding).
Thus: populates a field in the class with an appropriate implementation for the interface
Spring can do this, Pico can do this (and these frameworks can also do much more, they are not just about IoC, I understand that too, but in this particular context that is my concern, and frankly that is what I see 80% of Spring/Pico articles pertaining to). Yet I can do this also with a properties file, an interface, an implementation and a factory. The factory reads the properties file for the class which implements the interface and returns that at runtime. This is the same net effect, or rather I think this is the same net effect from the perspective of someone who doesnt yet see a blinding white light surrounding "Spring". (That light could yet show up, dont get me wrong, this is not an attempt to diss Spring, rather its an attempt to further figure out what I am missing.)
Result: properties.file/interface/impl/factory
So after looking at all sorts of possibilities, most of which are Hibernate and Spring oriented (such as Unruly Ramblings: Spring and Hibernate and the afore-article-mentioned Generic DAO pattern with Java 5.0) and then reading the Spring "reference" manual (ok, the parts of it that pertained to this and the intro stuff, not all of it), and then reading over the Hibernate manuals and then trying a few things, after all of that, I have landed at Hibernate 3 native (not annotations and entitymanager) and my own props/interface/impl/factory idiom.
Its not as fancy as Generic Data Access Objects or 12.2.5. Implementing DAOs based on plain Hibernate3 API but in my testing thus far it works and its ultra simple (with no dependencies beyond Hibernate and its lackeys).
Anyone out there with any advice please feel free to offer it. Suggestions, tips, links, whatever. I am still sort of feeling like I am oversimplifying things and not "getting" it - but since my straightforward idiom WORKS and is SIMPLE it is the choice thus far.







Comments
RE: DAOs and Hibernate and Spring and all that hullabaloo
RE: DAOs and Hibernate and Spring and all that hullabaloo