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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:08:30+00:00 2026-05-15T15:08:30+00:00

I need to centralize all settings for our Java web application in one .properties

  • 0

I need to centralize all settings for our Java web application in one .properties file. I can still have hibernate.cfg.xml for adding mappings to entity classes but I need to keep all of our settings for the database and custom paths in one .properties file.

Originally I kept my configs in hibernate.cfg.xml as follows….

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="connection.url">my jdbc connection</property>
        <property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
        <property name="connection.username">user</property>
        <property name="connection.password">password</property>
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
        <property name="hibernate.current_session_context_class">managed</property>
        <mapping class="myEntityClass"/>
    </session-factory>
</hibernate-configuration>

Now I want to move”connection.url”, “connection.username”, and “connection.password” to my own .properties file. The code for creating my hibernate configuration class went from.

new AnnotationConfiguration().configure();

to

new AnnotationConfiguration()
                .setProperty("connection.url", databaseUrl)
                .setProperty("connection.username", databaseUser)
                .setProperty("connection.password", databasePassword)
                .configure();

Which seemed conceptually simple. Unfortunately I get the following error when I try to use my Hibernate Session that worked with the previous config.

The user must supply a JDBC connection

Any ideas? It seems to me that when Hibernate sees these properties missing in the hibernate.cfg.xml file it assumes all settings will be manually added and ignore the xml altogether.

  • 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-15T15:08:30+00:00Added an answer on May 15, 2026 at 3:08 pm

    From the Hibernate Reference Documentation:

    3.3. JDBC connections

    […]

    The following is an example
    hibernate.properties file for c3p0:

    hibernate.connection.driver_class = org.postgresql.Driver
    hibernate.connection.url = jdbc:postgresql://localhost/mydatabase
    hibernate.connection.username = myuser
    hibernate.connection.password = secret
    hibernate.c3p0.min_size=5
    hibernate.c3p0.max_size=20
    hibernate.c3p0.timeout=1800
    hibernate.c3p0.max_statements=50
    hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
    

    Adapt it to suit your needs and put the hibernate.properties in the root of the class path (and remove the equivalent entries from the hibernate.cfg.xml as the XML configuration file overrides properties). So there is actually no need to change the following line:

    new AnnotationConfiguration().configure();
    

    Unless you really want a programmatic configuration of course.

    But from the body of your question, moving to a .properties file is something else and you can rely on Hibernate: move the relevant properties from hibernate.cfg.xml to hibernate.properties.

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

Sidebar

Ask A Question

Stats

  • Questions 486k
  • Answers 486k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There is the built-in DateTime class, but you don't even… May 16, 2026 at 8:05 am
  • Editorial Team
    Editorial Team added an answer You can tell Rails that the leader_id is really a… May 16, 2026 at 8:05 am
  • Editorial Team
    Editorial Team added an answer Base64-encoded data is about 1/3 larger than raw bytes, so… May 16, 2026 at 8:05 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.