0

I'm discovering Hibernate today, and I'm struggling while trying to make a minimal program find my "hibernate.cfg.xml" configuration file.

Here is what I already tried :

My main :

package testHibernate;

import org.hibernate.cfg.Configuration;

public class Main
{
    public static void main(String[] args)
    {
        Configuration configuration = new Configuration().configure();
    }
}

at the same level of this main file :

hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://www.hibernate.org/dtd/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/pianissimo</property>
       <property name="hibernate.connection.username">admin</property>
       <property name="hibernate.connection.password">nx5fDdVdEGVDS6Tq</property>
    </session-factory>
</hibernate-configuration>

Any help will be greatly appreciated :) Sincerely, Alann

Bacteria
  • 8,406
  • 10
  • 50
  • 67
Alann S.
  • 125
  • 12

1 Answers1

0

You shouldn't put hibernate.cfg.xml on the same level as your Main class. You should put it on the same level as your testHibernate package, in the root of the source folder. Or you need to specify a path to hibernate.cfg.xml like this

Configuration configuration = 
    new Configuration().configure("/testHibernate/hibernate.cfg.xml");
v.ladynev
  • 19,275
  • 8
  • 46
  • 67