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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:16:58+00:00 2026-05-24T14:16:58+00:00

This is question about java hibernate. my hibernate.cfg.xml is <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE hibernate-configuration

  • 0

This is question about java hibernate.

my hibernate.cfg.xml is

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/poc</property>
    <property name="hibernate.connection.username">user</property>
    <property name="hibernate.connection.password"/>
    <mapping class="test.person" file="" jar="" package="" resource="person.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

Connection to the database is working and I can explore databases and tables,

my sample

person.hbm.xml is

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-mapping>
    <class name="test.person" table="person">
        <id name="id" type="int" column="id" >
            <generator class="assigned"/>
        </id>
        <property name="fName">
            <column name="fName" />
        </property>
        <property name="lName">
            <column name="lName"/>
        </property>
        <property name="age">
            <column name="age"/>
        </property>
        <property name="gender">
            <column name="gender"/>
        </property>
    </class>
</hibernate-mapping>

this is my person class

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test;

public class person {

    private int id;
    private String fName;
    private String lName;
    private String gender;
    private int age;

    public person() {
        System.out.println("person");
    }

    public int getId() {
        return id;
    }

    public int getAge() {
        return age;
    }

    public String getfName() {
        return fName;
    }

    public String getGender() {
        return gender;
    }

    public String getlName() {
        return lName;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void setfName(String fName) {
        this.fName = fName;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public void setlName(String lName) {
        this.lName = lName;
    }

}

Here comes my Main class

package test;


import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class Test {

    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {


        Session session = null;
        SessionFactory sessionFactory =new Configuration().configure().buildSessionFactory();
        session = sessionFactory.openSession();

        person obj = new person();
        obj.setfName("Aqif");
        obj.setlName("Hamid");
        obj.setAge(24);
        obj.setGender("Male");

        session.save(obj);
        session.flush();
        session.close();

    }
}

I am getting this exception,

SEVERE: JDBC Driver class not found: org.apache.derby.jdbc.ClientDriver
java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:169)
    at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
    at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:61)
    at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
    at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
    at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
    at test.Test.main(Test.java:15)
Exception in thread "main" org.hibernate.HibernateException: JDBC Driver class not found: org.apache.derby.jdbc.ClientDriver
    at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:66)
    at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
    at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
    at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
    at test.Test.main(Test.java:15)
Caused by: java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:169)
    at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
    at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:61)
    ... 7 more
Java Result: 1

Please help me resolve these exceptions

I donot know why I am getting this exception

java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver

Where as my hibernate.cfg.xml is set for MySQL database


EDIT:

Location of files,

It is located at root of .java files

C:…..NetBeansProjects\test\src

That is src folder of my project.

and java files are in

C:…..NetBeansProjects\test\src\test

I have tried by coping my hibernate.cfg.xml file to some other locations as well.

  • 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-24T14:16:59+00:00Added an answer on May 24, 2026 at 2:16 pm

    The hibernate.cfg.xml must be present in the root of the classpath. Hibernate uses the current thread’s context classloader, to locate and load this file. This would mean that:

    • If the Test class is within a JAR, then the config file, must be at the root of the JAR.
    • If the Test class is in a directory, say /classes/test/Test.class, then hibernate.cfg.xml must be present in /classes.

    Your current issue would most likely be due to another hibernate.cfg.xml file being located and loaded by Hibernate. This is possible if no configuration file was found in the root of your class path; Hibernate then delegates the loading of the configuration file to the Environment class’ classloader, until it locates a configuration file. To avoid this, you must ensure that your desired config file, with the MySQL related properties, must be present in the root of your classpath.

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

Sidebar

Related Questions

This question is about a Java JTree or a Window .Net Tree (Winforms) or
This question is about Why does autoboxing make some calls ambiguous in Java? But
I came across this question about callbacks in Java. Hers is the running code
This is a brainstorming question about what's possible in Java (or not). I want
hello I have some question about writing class in Java, why this one is
This question is about the Java API of Selenium 2 RC2, used with Firefox
This question has been discussed in two blog posts ( http://dow.ngra.de/2008/10/27/when-systemcurrenttimemillis-is-too-slow/ , http://dow.ngra.de/2008/10/28/what-do-we-really-know-about-non-blocking-concurrency-in-java/ ),
This question is a follow up to my previous question about getting the HTML
I was reading this question about how to parse URLs out of web pages
I just came across this question about initializing local variables. Many of the answers

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.