1

This is my hibernate config file. I put it in src/main/resources and I put it in src .

But all the time I get this error:

Could not locate cfg.xml resource [hibernate.cfg.xml]

<?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.show_sql">true</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    </session-factory>
</hibernate-configuration>

This is how I wrote my config file. I am using spring. I just found out that actually all this is not necessary in spring. You could just autowire SessionFactory.

Alicia17
  • 75
  • 5

1 Answers1

0

You can place: hibernate.cfg.xml file to

src/main/resources/hibernate.cfg.xml

or persistence.xml file to

src/main/resources/META-INF/persistence.xml

If you are using Hibernate's proprietary API, you'll need the hibernate.cfg.xml. If you are using JPA i.e. Hibernate EntityManager, you'll need the persistence.xml.

Roman Motovilov
  • 344
  • 3
  • 5