Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7565923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:16:54+00:00 2026-05-30T14:16:54+00:00

I have 2 separate modules in separate .jars which operate on 2 different databases.

  • 0

I have 2 separate modules in separate .jars which operate on 2 different databases.

The applicationContext-hibernate.xml files contain unique names for the session factories, and the web.xml loads (should load? I hope so.) both context.xml files. I also defined one of the custom sessionFactory namesin the web.xml, as you cen see here:

web.xml

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:/applicationContext-hibernate.xml</param-value>
</context-param>
[...]
<filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>
        org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    </filter-class>
    <init-param>
        <param-name>sessionFactoryBeanName</param-name>
        <param-value>customsessionFactory</param-value>
    </init-param>
</filter>

So the first database connection works as intended. But how do I go about to add the second one?
Only one of the database beans is available from the context (of course, since the other one is not added)

I only found “How to handle multiple database connections using session factories with Spring and Hibernate” but I don’t understand the answer there.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T14:16:55+00:00Added an answer on May 30, 2026 at 2:16 pm

    as long as you have defined the 2 sessionFactories with different ID’s.. you can pass the path of the 2nd xml file seperating it with a comma

    <param-value>classpath*:/applicationContext-hibernate.xml, <<2nd file reference>></param-value>
    

    Once you have this setup.. spring will be able to init 2 sessionFactories..

    – Option 1

    you need to create 2 instances of hibernateTemplate (one for each session Factory) and inject them both into your DAO, this way you can use the hibernatetemplate to work with multiple sessionFactories..

    – Option 2

    while working with HibernateDaoSupport you can use the method createHibernateTemplate(sesionFactoryReference) to create a template object with a specific sessionFactory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering about this... I have several separate javascript files, that all contain code
We're using maven 2.1.0. I have multiple modules that are completely separate, but still
I have web application which we deployed in a production . We have separate
I'm writing a testing framework using Python's unittest. I have separate modules for separate
I have an android application which contains four modules(I mean four apk's).Each module has
I have a function in a file which I am calling in a separate
I'm working on a Python web application in which I have some small modules
I have an intranet application with several modules, I want them to separate when
We develop new modules for our application on separate branches. When they have been
Do I need to have separate/multiple workers to run multiple websites (each with a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.