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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:42:45+00:00 2026-06-14T23:42:45+00:00

Hibernate needs you to map all your Entity classes in Hibernate.cfg.xml, but I don’t

  • 0

Hibernate needs you to map all your Entity classes in Hibernate.cfg.xml, but I don’t want to list all of them. I just want to reference the package in which they are all contained. I’ve read that Spring allows your application to autodiscover all your annotated classes with a bean for AnnotationSessionFactoryBean, but I don’t understand how and where I’m supposed to configure this. I do NOT have a persistence.xml file anywhere in my application ==> I’m using Hibernate (Session instead of EntityManager, etc).

  • 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-14T23:42:47+00:00Added an answer on June 14, 2026 at 11:42 pm

    First of all clarify whether you’re using JPA or Hibernate directly.
    If you don’t have any persistence.xml it might be that you’re not using JPA (I would recommend using it though, you’ll still be using Hibernate underneath, but your code will be more standard and independent of Hibernate).

    Spring does support auto scanning of entity classes through:

    <context:component-scan base-package="your.package.name" />
    

    I know it works for JPA, not sure for Hibernate directly.

    My working spring application config file snippet looks like this, which includes the Hibernate properties (thus eliminating the need of the file completely):

    <context:component-scan base-package="your.package.name" />
    <tx:annotation-driven transaction-manager="transactionManager"/>
    
    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
    
    <bean id="transactionManager"
          class="org.springframework.orm.jpa.JpaTransactionManager"
          p:entityManagerFactory-ref="entityManagerFactory" />
    
    <bean id="entityManagerFactory"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
          p:persistenceUnitName="persistenceUnitName">  <!-- this comes from persistence.xml -->
    
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
        </property>
    
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.hbm2ddl.auto">validate</prop>
                <prop key="hibernate.connection.provider_class">org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider</prop>
    
                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQL82Dialect</prop>
                <prop key="hibernate.connection.driver_class">org.postgresql.Driver</prop>
                <prop key="hibernate.connection.url">jdbc:postgresql://localhost:5432/myDB</prop>
                <prop key="hibernate.connection.username">username</prop>
                <prop key="hibernate.connection.password">password</prop>
    
                <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
                <prop key="hibernate.id.new_generator_mappings">true</prop>
                <prop key="hibernate.show_sql">false</prop>
                <prop key="hibernate.jdbc.batch_size">50</prop>
                <prop key="hibernate.id.new_generator_mappings">true</prop>
                <prop key="hibernate.c3p0.maxSize">100</prop>
                <prop key="hibernate.c3p0.minSize">10</prop>
                <prop key="hibernate.c3p0.acquireIncrement">10</prop>
                <prop key="hibernate.c3p0.idleTestPeriod">300</prop>
                <prop key="hibernate.c3p0.maxStatements">0</prop>
                <prop key="hibernate.c3p0.timeout">1800</prop>
                <prop key="hibernate.c3p0.checkoutTimeout">0</prop>
                <prop key="hibernate.c3p0.preferredTestQuery">SELECT 1;</prop>
            </props>
        </property>
    </bean>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to map two different classes to the same view and receive an
I have a complex situation, where I need to map three different classes with
I have a Domain that I generate using Entity Developer. This creates all of
I have ~40 classes, and they all implement an interface IEntity. Of the ~40
I've recently started using Hibernate and am trying to get my head around all
I have some big data objects, stored in CompressedData property, so I don't want
Is there a way to map an Entity class (Address.java) to MySQL without using
I get object from hibernate query. Then i have list of fields, whose getters
I have spring/hibernate web app. I use Hibernate to implement almost all of my
I need this roadmap of a Hibernate managed object instance. First, I create an

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.