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 8670077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:37:46+00:00 2026-06-12T18:37:46+00:00

I have a hibernate.cfg.xml file, but I’d like to reference it as a dataSource

  • 0

I have a hibernate.cfg.xml file, but I’d like to reference it as a dataSource bean. Is there any way to do this? All I have is :

<beans:bean id="foo" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <beans:property name="configLocation" value="classpath:hibernate.cfg.xml"/>

but its not a dataSource. Any help would be greatly appreciated.

To add a bit of context, I’d like to integrate Spring Security in my app and one of the ways to provide a database as a source for the authentication manager is as follows (taken from here):

   <authentication-manager>
        <authentication-provider>
            <jdbc-user-service data-source-ref="securityDataSource"/>
        </authentication-provider>
    </authentication-manager>

Where “securityDataSource” is the name of a DataSource bean in the application context, pointing at a database.

  • 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-06-12T18:37:48+00:00Added an answer on June 12, 2026 at 6:37 pm

    You have two options:

    1. If you’re not using the hibernate.cfg.xml anywhere else, you can eliminate it altogether and just use Spring’s configuration (see below)

    2. If you need hibernate.cfg.xml for some reason (you’re using it elsewhere), then keep that file and add Spring configuration


    Example configuration (notice database access is in a separate dataSource bean)

    <beans:bean id="foo" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
           <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.hbm2ddl.auto">create-drop</prop>
                    ...
            </property>
            <property name="packagesToScan">
                <list>
                    <value>some.package</value>
                </list>
            </property>
        <property name="dataSource" ref="c3p0DataSource" />
    
    <bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
        scope="singleton"
            destroy-method="close">
            <property name="driverClass">
                <value>org.postgresql.Driver</value>
            </property>
            <property name="jdbcUrl">
                <value>${jdbc.url}</value>
            </property>
            <property name="user">
                <value>${jdbc.user}</value>
            </property>
            <property name="password">
                <value>${jdbc.pw}</value>
            </property>
        </bean>
    

    You can see more information about the configuration options in http://static.springsource.org/spring/docs/current/spring-framework-reference/html/orm.html

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

Sidebar

Related Questions

I have JRE 1.6 and am using the following hibernate.cfg.xml file. I am always
I have hibernate.cfg.xml file. <session-factory> <!-- Database connection settings --> <property name=connection.driver_class>com.mysql.jdbc.Driver</property> <property name=connection.url></property>
I have my hibernate.cfg.xml file as, <hibernate-configuration> <session-factory> <property name=hibernate.bytecode.use_reflection_optimizer>false</property> <property name=hibernate.connection.driver_class>com.mysql.jdbc.Driver</property> <property name=hibernate.connection.password>123789</property>
in common, hibernate sessionfactory is created in spring configuration file (eg spring-dao.xml) like; <bean
I have my hibernate.cfg.xml There is field: <property name=hibernate.connection.username>username</property> // getUser()??? I have class
I have pasted Hibernate 3 configuration file , SessionFactory class to configure this config.xml
I do not want to have the hibernate.cfg.xml file. Rather I want to do
I have a Hibernate mapping that looks something like this: <class name=MyEntity> <set name=scalarSet
I,m having trouble with my hibernate.cfg.xml actually it works but after I'm uninstalled webnms
I have the following mapping file: <?xml version=1.0 encoding=utf-8 ?> <hibernate-mapping xmlns=urn:nhibernate-mapping-2.2 assembly=Project1.Accounts namespace=Project1.Core.Domain>

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.