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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:45:55+00:00 2026-06-15T04:45:55+00:00

I’m using Spring 3.1.2 and Hibernate 4.1.7 for my web application. I want to

  • 0

I’m using Spring 3.1.2 and Hibernate 4.1.7 for my web application. I want to now configure both of these. I have my hibernate.cfg.xml file:

<hibernate-configuration>
    <session-factory>
        <property name="connection.url">jdbc:mysql://localhost:3306/test</property>
        <property name="connection.username">root</property>
        <property name="connection.password">root</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.pool_size">10</property>
        <property name="hibernate.connection.autocommit">false</property>
        <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
        <!-- 
        <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
         -->
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.hbm2ddl.auto">update</property>       
    </session-factory>
</hibernate-configuration>

My webapp-servlet.xml spring config file:

<beans>
<bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="configLocation">
        <value>
            classpath:hibernate.cfg.xml
        </value>
    </property>
    <property name = "dataSource" ref = "dataSource"></property>
</bean>

<bean id = "dataSource" class = "org.apache.commons.dbcp.BasicDataSource">
    <property name = "driverClassName" value = "com.mysql.jdbc.Driver" />
    <property name = "url" value = "jdbc:mysql://localhost:3306/test" />
    <property name = "username" value = "root" />
    <property name = "password" value = "root" />
    <property name = "maxActive" value = "10" />
</bean>
</beans>
  1. Why do I need to configure a DataSource bean when all of the data needed is already included in the hibernate configuration file? Does Hibernate have some default it can use?
  2. What are some other DataSources I can use?
  3. Am I missing any other beans or configuration parameters/properties to get hibernate working with my application?
  • 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-15T04:45:56+00:00Added an answer on June 15, 2026 at 4:45 am
    1. You don’t need both of them. You can either get rid of hibernate.cfg.xml and configure everything in LocalSessionFactoryBean, or reuse your existing hibernate.cfg.xml as is (in this case you don’t need to configure DataSource in Spring config).

    2. You have the following options:

      • Use embedded database – it’s good for testing and learning purposes

      • Use DriverManagerDataSource – it’s a simple non-pooled datasource that can be used for testing, etc (not recommended for production use)

      • Use connection pool such as DBCP or c3p0

      • If you deploy to application server you can use connection pool provided by the application server using JNDI

    3. Your current configuration is sufficient, but it lacks support of Spring transaction management. In order to enable it you need to

      • Declare HibernateTransactionManager

      • Add <tx:annotation-driven> to enable declarative transaction management (@Transactional)

      • Declare TransactionTemplate if you want to use programmatic transaction management (use it to overcome limitations of declarative transaction management)

      • Also don’t forget to remove transaction-related properties from Hibernate configuration since they may conflict with Spring transaction management

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

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I have thousands of HTML files to process using Groovy/Java and I need to

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.