Announcement Announcement Module
Collapse
No announcement yet.
How to wire a SingleConnectionDataSource to HibernateDaoSupport? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to wire a SingleConnectionDataSource to HibernateDaoSupport?

    I have a JDBC Connection at runtime, and wrap it into a SingleConnectionDataSource (suppressClose). How can I use it to build a SessionFactory, which will be used in a HibernateDaoSupport? I tried to use LocalSessionFactoryBean, but it is supposed to be used at configuration time, not runtime.

    The bigger question is how to use an always-open session (connection) in Spring and Hibernate? I am tired of "owning session closed" errors.

  • #2
    The bigger question is how to use an always-open session (connection) in Spring and Hibernate? I am tired of "owning session closed" errors.
    For this you can use OpenSessionInViewFilter/Interceptor. as for the datasource, inject is as a normal datasource but configure it at runtime. Take a look at the various TargetSources from aop package like :http://static.springframework.org/sp...getSource.html

    Comment


    • #3
      OpenSessionInViewFilter/Interceptor is for web application. Sessions will still be closed once view logic is complete. I am developing a stand-alone application. I can afford an always-open session (connection). Shall I still use the OpenSessionInViewInterceptor, subclass it, or use something else designed for standalone applications?

      Comment


      • #4
        Yes, subclass or 'get inspired' by OpenSessionInViewFilter/Interceptor for your situation. OpenSessionInView uses http request boundaries - subclass to use the ones you defined.

        Comment

        Working...
        X