Well, in moment ( for me, personally ) hibernate is not very pico friendly - though emplying pico would make my project more friendly to me ( a lot of config / glue stuff would just dissapear without a trace -
like in other parts )
Session lifetime is not very clear, so there will be need of some kind of "session provider" - it has to have session factory (because session factory can be obtained through configuration only, there will be need in some adapter. Pretty trivial though)
The this session profived component shall provide methods:
- to obtain session ( maybe already used session , cache it, use thread local)
- to give session back ( without closing it )
- to give botched session back and destroy it ( after exception , maybe provide rollback )
- ( possible ) explicit transaction demarcation
DAO shall eat this session provider, and be really simple in the init
( mine are already ) to be constructed effectively and just disposed.
If DAO itself is threadsafe, it could live as application scopre component, where session provider is request scope...
|