Library to config Hibernate that allows instances of key interfaces rather than simply classnames and properties or string
I really hate how Hibernate does not allow one to simply set a TransactionManager or CacheProvider and all the other important interfaces on a Configuration. Instead it has variations such as taking a classname or a classname to a lookup or pro开发者_开发技巧vider. Again it simply is not possible to pass the instance directly and one must use hacks such as setting a threadlocal, setting some class locator name and have it read the threadlocal back. Ugly nasty etc etc. Surely someone has cleaned this all up, which is why i am asking the q.
RANT
Think how much simpler the Config objects would be if one could simply set, the Configuration class would no longer have dozens and dozens of String properties and would be easily injectable.
- the pool
- transaction manager lookup
- cache provider
- data source
Simplicity
Writing new providers would become so much easier, no longer would one have to reinvent a protocol to read config from a string(s) and an adapter. With proper dependency injection one would only need to write the latter
WORKING SOLUTION I started work by sub classing some Hibernate classes so i can replace the default with an instance or wrapper.
- Configuration - must create a sub classs that takes a SessionFactory because the ctor taking a SessionFactory is protected. No other methods are touched.
- SettingsFactory - override key methods to return instance.
etc.
writing my own SessionFactory
精彩评论