user911651
user911651

Reputation:

Netbeans 7.1 Hibernate Reverse Engineering wizard does not find database driver

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>

Upvotes: 4

Views: 15072

Answers (6)

user2303661
user2303661

Reputation: 1

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

Upvotes: 0

Mohammed Saqib Rajput
Mohammed Saqib Rajput

Reputation: 1370

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>

Upvotes: 3

Jason Glez
Jason Glez

Reputation: 1512

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

Upvotes: 1

user2066936
user2066936

Reputation:

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.)

Upvotes: 0

hello
hello

Reputation: 11

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

Upvotes: 1

Anthony Accioly
Anthony Accioly

Reputation: 22471

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.

Upvotes: 0

Related Questions