I don't understand the problem. You write the DAOs as objects that use the ThreadLocal Session. Then
whoever is calling the DAOs is responsible for setting up and closing the Session for that thread.
In other words, you have:
Code:
SomeCallerMethod (servlet method, standalone app method, whatever)
CreateThreadLocalSession
CallDao1
GetThreadLocalSession
DoHibernateStuff
CallDao2
GetTLS
DoHibernateStuff
Flush
CloseSession
End SomeCallerMethod
So the DAOs have no idea who is calling them. All they know is they can get a ThreadLocalSession to do their job with.
I know this works since we have exactly the same pattern. We have DAOs that are used either in our beans or in our unit tests (i.e. our stand-alone JUnit classes). They work just fine in either place, getting their TLS from our singleton Persistence Hibernate-wrapper class.
Cheers
Rob