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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:27:55+00:00 2026-06-11T06:27:55+00:00

I want to insert to my postgresql database using hibernate and I quite or

  • 0

I want to insert to my postgresql database using hibernate and I quite or haven’t figure out why I keep getting this error, What I’m trying to do is I let the hibernate create my database table and column and insert to the created table. So my first error is about the missing jar files which is the slf4j which I already added to my Hibernate library, However after I run the application again new error pops up so this are my error:

90 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons 

Annotations 3.2.0.Final
100 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.6.10.Final
100 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
100 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
100 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
150 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
150 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found
    at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:170)
    at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:2176)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:2157)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:2137)
    at org.hibernate_main.HibernateMain.main(HibernateMain.java:13)

This are my Jar File(int the Hibernate library):

hibernate3.jar
antlr-2.7.6.jar
commons-collections-3.1.jar
dom4j-1.6.1.jar
javassist-3.12.0.GA.jar
jta-1.1.jar
slf4j-api-1.6.1.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
postgresql-9.1-902.jdbc4

And my code:
Configuration(XML)

<?xml version="1.0" encoding="UTF-8"?>

<!-- ~ Hibernate, Relational Persistence for Idiomatic Java ~ ~ Copyright (c) 2010, Red Hat Inc. or third-party contributors as ~ indicated by the @author tags or express copyright attribution ~ statements applied by the authors. All third-party contributions are ~ distributed under license by Red Hat Inc. ~ ~ This copyrighted material is made available to anyone wishing to use, modify, ~ copy, or redistribute it subject to the terms and conditions of the GNU ~ Lesser General Public License, as published by the Free Software Foundation. ~ ~ This program is distributed in the hope that it will be useful, ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License ~ for more details. ~ ~ You should have received a copy of the GNU Lesser General Public License ~ along with this distribution; if not, write to: ~ Free Software Foundation, Inc. ~ 51 Franklin Street, Fifth Floor ~ Boston, MA 02110-1301 USA -->

<!DOCTYPE hibernate-configuration SYSTEM "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd" PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN">
-<hibernate-configuration> -<session-factory> 
<!-- Database connection settings -->
 <property name="connection.driver_class">org.postgresql.Driver</property> 
 <property name="connection.url">jdbc:postgresql://localhost:5432:MYPOS</property> 
 <property name="connection.username">postgres</property> 
 <property name="connection.password"/>perbert101
<!-- JDBC connection pool (use the built-in) -->
 <property name="connection.pool_size">1</property> 
<!-- SQL dialect -->
 <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property> 
<!-- Disable the second-level cache -->
 <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> 
<!-- Echo all executed SQL to stdout -->
 <property name="show_sql">true</property> 
<!-- Drop and re-create the database schema on startup -->
 <property name="hbm2ddl.auto">create</property> 
<!-- Names the annotated entity class -->
 <mapping class="org.user_detail.dto.UserDetail"/> </session-factory> </hibernate-configuration>

UserDetail Class:

package org.user_detail.dto;
import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class UserDetail {
    @Id
    private int userId;
    private String userName;

    public int getUserId() {
        return userId;
    }
    public void setUserId(int userId) {
        this.userId = userId;
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }

}

My Main Class:

package org.hibernate_main;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.user_detail.dto.UserDetail;

public class HibernateMain {
    public static void main(String[] args){
        UserDetail user = new UserDetail();
        user.setUserId(1);
        user.setUserName("Jerome");

        SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
        Session session = sessionFactory.openSession();
        session.beginTransaction();
        session.save(user);
        session.getTransaction().commit();
    }
}

Guys can you tell me what this error was and how to fix them, and how to test if the database connection in the XML is success or failed. thanks guys.

  • 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-11T06:27:57+00:00Added an answer on June 11, 2026 at 6:27 am

    I think

      /hibernate.cfg.xml not found
    

    is clear enough.

    Make sure it’s in the CLASSPATH.

    You can also specify it in:

    return new Configuration().configure("/path/to/hibernate.cfg.xml" ).buildSessionFactory();
    

    in your code above

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

Sidebar

Related Questions

I want to insert data into the postgresql database of OpenERP, I am able
I want to insert a record into a MySQL database table from a formulaire.
I want to insert a date record to an Access database. Here is my
I want to insert the following include tag into my webpage using JavaScript. <!--#include
I am trying to move dumped data from postgresql database to another. However, when
In my program, I am accessing Postgresql database. I don't want to watch database
I'm using Npsql with PostgreSQL. I want to see uncommitted changes of one transaction
I'm using eclipselink as JPA Implementation and PostgreSQL and want to store SHA-1 Hashes
I'm using Elixir in a project that connects to a postgres database. I want
The situation is something like this: PostgreSQL Database table has a field dateAdded which

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.