Netbeans 7.1 Hibernate Reverse Engineering wizard does not find database driver

14,366

Solution 1

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>

Solution 2

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

Solution 3

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

Share:
14,366
AlexLiesenfeld
Author by

AlexLiesenfeld

Updated on June 04, 2022

Comments

  • AlexLiesenfeld
    AlexLiesenfeld almost 2 years

    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>
    
  • AlexLiesenfeld
    AlexLiesenfeld over 12 years
    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.
  • Anthony Accioly
    Anthony Accioly over 12 years
    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?
  • AlexLiesenfeld
    AlexLiesenfeld over 12 years
    yes, there are these libs. 1) Hibernate 2) Persistence 3) MySQL JDBC Driver 4) EclipseLink(JPA2.0)
  • Anthony Accioly
    Anthony Accioly over 12 years
    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.
  • AlexLiesenfeld
    AlexLiesenfeld over 12 years
    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.
  • Anthony Accioly
    Anthony Accioly over 12 years
    Humm... I'm not able to reproduce the bug here (Windows 7, Java 7 64 Bits, Netbeans 7.1). You may consider filling a Bug Report.
  • javatestcase
    javatestcase over 12 years
    I'm using the Maven plugin version of hbm2java, and a hibernate.properties filed. Are you using Maven in your project? If so, I'll post my code up to get you moving...
  • AlexLiesenfeld
    AlexLiesenfeld over 12 years
    No I don't. But, I found out that this issue is caused by a netbeans 7.1 rev.eng. wizard bug. I am able to reproduce this error. In comparison, using netbeans 6.9.1 EXACTLY the same procedure works like a charm!
  • Anthony Accioly
    Anthony Accioly over 12 years
    You should upload a sample project to the Netbeans team. I've reversed engineered the sample Derby database in a empty project (by using the wizards to create a hibernate.cfx.xml, hibernate.reveng.xml, POJOS and mappings) and it worked successfully. I believe that your bug is either environment or MySQL specific. As a workaround, for now, as suggested by @javatestcase you can use hibernate tools with a Ant Build Script or Maven and call it's targets / goals through the IDE.