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

  • Home
  • SEARCH
  • 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 3316164
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:26:13+00:00 2026-05-17T22:26:13+00:00

im using hibernate and i maps my entities with annotations (so no xml files).

  • 0

im using hibernate and i maps my entities with annotations (so no xml files).

I finally decided to try spring framework but I encountered some problems to make it work.

All tutorials i found are very dispersive and most of them use xml file to map an entity…
Can you help me to correctly write a xml config file for spring+hibernate?

Thanks.

  • 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-17T22:26:14+00:00Added an answer on May 17, 2026 at 10:26 pm

    The following is a working example from one of my apps.
    They should all go in the applicationContext or in a .xml loaded by the appContext.

    The first snippet is the configuration of the datasource, using connection pooling:

    <bean id="dataSource"
        class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"
        p:driverClass="${jdbc.driverClassName}"
        p:jdbcUrl="${jdbc.url}"
        p:user="${jdbc.username}"
        p:password="${jdbc.password}" />
    

    Next up is a Property bean. If you are unsure about any of these settings, please refer to the corresponding APIs.

    <bean id="hibernateProps" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="properties">
            <props>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                <prop key="hibernate.show_sql">false</prop>
                <prop key="hibernate.c3p0.minPoolSize">5</prop>
                <prop key="hibernate.c3p0.maxPoolSize">20</prop>
                <prop key="hibernate.c3p0.idleTestPeriod">300</prop>
                <prop key="hibernate.c3p0.timeout">600</prop>
                <prop key="hibernate.c3p0.max_statement">50</prop>
                <prop key="hibernate.c3p0.testConnectionOnCheckout">false</prop>
                <prop key="hibernate.c3p0.preferredTestQuery">select 1;</prop>
            </props>
        </property>
    </bean>
    

    Now this is the interesting part. Here you wire it all together and tell the sessionfactory where to look for annotated Classes (packagesToScan).

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
          p:dataSource-ref="dataSource"
          p:packagesToScan="your.package.path"
          p:hibernateProperties-ref="hibernateProps" />
    

    To make this example work, you should use the following dependencies (given for maven):

        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>persistence-api</artifactId>
            <version>1.0</version>
        </dependency>
    
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>3.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>3.0.2.RELEASE</version>
        </dependency>
    
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate</artifactId>
            <version>3.2.7.ga</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.3.0.ga</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>3.3.0.ga</version>
        </dependency>
    
        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.1</version>
        </dependency>
    

    When you have setup your project like this, the following @Entity mappings are managed by spring automatically:

    package your.package.path;
    
    import java.io.Serializable;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.Table;
    import javax.persistence.Transient;
    
    @Entity
    @Table(name = "table_name")
    public class DomainObject implements Serializable {
    
    .
    .
    .
    }
    

    If you have any further questions, please let me know.

    greetings

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

Sidebar

Related Questions

I'm using hibernate validator framework with Spring. A class implementing the Spring Validator validates
We are using Hibernate 3.1 with Spring MVC 2.0. Our problem occurs when data
I'm using Hibernate with Spring in my application. I have been consistently using detached
I am using Hibernate in a Java application to access my Database and it
I am currently using Hibernate Tools 3.1; I customized naming convention and DAO templates.
I'm using Hibernate for ORM of my Java app to an Oracle database (not
So I'm using hibernate and working with an application that manages time. What is
I'm using hibernate 3 and want to stop it from dumping all the startup
I am using Hibernate 3.x, MySQL 4.1.20 with Java 1.6. I am mapping a
I'm using Hibernate's implementation of JPA and am seeing poor performance as multiple SQL

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.