数据库
首页 > 数据库> > java – Netbeans 7.1 Hibernate Reverse Engineering向导找不到数据库驱动程序

java – Netbeans 7.1 Hibernate Reverse Engineering向导找不到数据库驱动程序

作者:互联网

我目前正在尝试通过这个netbeans hibernate JavaSE教程(http://netbeans.org/kb/docs/java/hibernate-java-se.html).一切都很好,但是在创建hibernate.cfg.xml之后,当涉及到应该应用逆向工程的部分时,反向工程向导会告诉我一些奇怪的消息:

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

嗯,这有点奇怪,因为hibernate.cfg.xml是由netbeans生成的.我已经用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.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>

解决方法:

在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>

标签:java,hibernate,reverse-engineering,netbeans
来源: https://codeday.me/bug/20190626/1292178.html