El asistente de ingeniería inversa de Netbeans 7.1 Hibernate no encuentra el controlador de la base de datos

I am currently trying to get through this netbeans + hibernate + JavaSE tutorial ( http://netbeans.org/kb/docs/java/hibernate-java-se.html). All is pretty fine, but after the creation of the hibernate.cfg.xml when it comes to the part where reverse engineering should be applied it comes to some weird message that the reverse-engineering wizard tells me:

"The database drivers are not added to the project classpath." 
"Go to project properties to add database library.". 

Well that's kind of weird, because the hibernate.cfg.xml was generated by netbeans. I've checked my database connection with the connection data from the hibernate.cfg.xml and it seems to be all okay, so connecting manually works pretty fine. Anyone knows what is going on here? Am I doing something wrong?

<?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/sakila</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">apassword</property>
     <property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
  </session-factory>
</hibernate-configuration>

preguntado el 01 de febrero de 12 a las 22:02

6 Respuestas

Add these line of code in hibernate.cfg.xml

<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/DATABASE_NAME</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"/>
</session-factory>

Respondido 03 ago 16, 09:08

Besides missing jar files, here is another possible way that could cause this error in netbeans: wrong configuration file.

So make sure you have the correct configuration file (.cfg.xml file) to build .reveng

Respondido 10 Jul 13, 04:07

Attached an example configuration:

<?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.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.password">1234</property>
    <property name="hibernate.connection.url">jdbc:mysql://161.58.103.144:3306/exampleDatabase?zeroDateTimeBehavior=convertToNull</property>
    <property name="hibernate.connection.username">JasonGlez</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  </session-factory>
</hibernate-configuration>

Just change the ip, the name of the database, your username and password

Respondido 14 Jul 16, 08:07

You are missing the JDBC Driver. At the Project View right click the Libraries node under your project and choose Add Library... -> MySQL JDBC Driver.

Respondido 02 Feb 12, 02:02

unfortunately this is not the case. I have the jdbc driver on the classpath and it seems to work the right way, because I can connect manually (by code) using it. - AlexLiesenfeld

Weird. When you right click your project and choose Properties, is the JDBC driver listed as a Compile library? Have you tried to clean and build your project? - Anthony Accioly

yes, there are these libs. 1) Hibernate 2) Persistence 3) MySQL JDBC Driver 4) EclipseLink(JPA2.0) - AlexLiesenfeld

Somehow Netbeans configured two conflicting JPA providers for your project. Try to remove all of those but MySQL JDBC Driver and add Hibernate JPA (if you are using JPA).Or maybe remove only EclipseLink (if you don't use JPA) and make sure there is no persistence.xml file around. - Anthony Accioly

Still the same. I assume there is some bug with the rev.eng.-wizard, because the mapping wizard works fine with this connection information held in hibernate.cfg.xml, also I can connect manually using the SessionFactory object inside my application. - AlexLiesenfeld

As mentioned by hello, make sure the hibernate.cfg.xml is good. Try regenerating it though from Netbeans Hibernate Configuration Wizard as opposed to crafting it yourself. Also try recreating the project and make sure the new project wizard populates the hibernate.cfg.xml with database connection settings. It came out blank for me the first time; not sure why. Before it started working, I had also restarted Netbeans and the computer to boot, which might not hurt to try. (No pun intended.)

contestado el 16 de mayo de 16 a las 01:05

This required MySQL driver, Add My sql Driver in Library to resolve the issue

Respondido el 06 de Septiembre de 17 a las 16:09

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.