Java Netbeans 7.1 Hibernate反向工程向导找不到数据库驱动程序

Java Netbeans 7.1 Hibernate反向工程向导找不到数据库驱动程序,java,hibernate,netbeans,reverse-engineering,Java,Hibernate,Netbeans,Reverse Engineering,我目前正在尝试完成这个netbeans+hibernate+JavaSE教程()。一切都很好,但是在创建hibernate.cfg.xml之后,当涉及到应该应用反向工程的部分时,出现了一些奇怪的消息,反向工程向导告诉我: "The database drivers are not added to the project classpath." "Go to project properties to add database library.". 这有点奇怪,因为hibernate.cf

我目前正在尝试完成这个netbeans+hibernate+JavaSE教程()。一切都很好,但是在创建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>

org.hibernate.dialogue.mysqldialogue
com.mysql.jdbc.Driver
jdbc:mysql://localhost:3306/sakila
根
阿帕斯word
org.hibernate.hql.classic.ClassicQueryTranslatorFactory

您缺少JDBC驱动程序。在项目视图中,右键单击项目下的
节点,然后选择
添加库…->MySQL JDBC驱动程序

除了缺少jar文件之外,还有另一种可能导致netbeans出现此错误的方法:错误的配置文件


因此,请确保您有正确的配置文件(.cfg.xml文件)来构建.reveng

正如hello所提到的,请确保hibernate.cfg.xml是良好的。尝试从Netbeans Hibernate配置向导重新生成它,而不是自己制作。还要尝试重新创建项目,并确保“新建项目向导”使用数据库连接设置填充hibernate.cfg.xml。对我来说,第一次是一片空白;不知道为什么。在它开始工作之前,我还重新启动了Netbeans和要引导的计算机,这可能不会对尝试造成伤害。(没有双关语。)

附上一个配置示例:

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

com.mysql.jdbc.Driver
1234
jdbc:mysql://161.58.103.144:3306/exampleDatabase?zeroDateTimeBehavior=convertToNull
贾松列兹
org.hibernate.dialogue.mysqldialogue

只需更改ip、数据库名称、用户名和密码

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

org.hibernate.dialogue.mysqldialogue
com.mysql.jdbc.Driver
jdbc:mysql://localhost/DATABASE_NAME
根

这是必需的MySQL驱动程序,请在库中添加我的sql驱动程序以解决此问题

不幸的是,情况并非如此。我在类路径上有jdbc驱动程序,它似乎工作正常,因为我可以使用它手动(通过代码)连接。右键单击项目并选择
Properties
时,JDBC驱动程序是否列为
编译库?您是否尝试过清理和构建您的项目?是的,有这些LIB。1) Hibernate 2)Persistence 3)MySQL JDBC驱动程序4)EclipseLink(JPA2.0)Netbeans以某种方式为您的项目配置了两个冲突的JPA提供程序。尝试删除除MySQL JDBC驱动程序之外的所有驱动程序并添加Hibernate JPA(如果您使用JPA)。或者只删除EclipseLink(如果您不使用JPA),并确保没有persistence.xml文件。仍然相同。我假设rev.eng.-向导有一些bug,因为映射向导可以很好地处理hibernate.cfg.xml中保存的连接信息,我也可以在应用程序中使用SessionFactory对象手动连接。