I'm having the hardest time getting Eclipse to connect and reverse engineer from a MySQL5 database. I can see Eclipse connecting to my MySQL database and can even see the tables through the "Data Source Explorer" view but when I try it after creating Hibernate Console and Configuration files, I get the error:
我正在努力让Eclipse从MySQL5数据库连接和逆向工程。我可以看到Eclipse连接到我的MySQL数据库,甚至可以通过“Data Source Explorer”视图查看表,但是当我在创建Hibernate控制台和配置文件后尝试它时,我收到错误:
org.hibernate.console.HibernateConsoleRuntimeException:
Problems while loading database
driverclass (com.mysql.jdbc.Driver)
Problems while loading database
driverclass (com.mysql.jdbc.Driver)
java.lang.ClassNotFoundException:com.mysql.jdbc.Driver
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
From my simple java project, I start by creating a Hibernate Configuration File (cfg.xml).
从我的简单java项目开始,我首先创建一个Hibernate配置文件(cfg.xml)。
Name of file: hibernate.cfg.xml
Session Factory name: org.hibernate.SessionFactory
Database Dialect: org.hibernate.dialect.MySQL5Dialect
Driver Class: com.mysql.jdbc.Driver
Connection Url: jdbc:mysql://localhost:3306/<myDatabaseName>
Default Schema: <myDatabaseName>
Username: correct username
Password: correct password
I also have selected the option to "Create a console Configuration"
我也选择了“创建控制台配置”选项
At this point, I can see the new configuration listed in my "Hibernate Configuration" perspective/workbench pane. If I try to expand it, I get the earlier listed error.
此时,我可以在“Hibernate Configuration”透视图/工作台窗格中看到新配置。如果我尝试扩展它,我会得到前面列出的错误。
I don't understand why I can see the database through the 'Data Source Explorer" and even though I'm using the DB connection profile listed in there as part of my configuration, I still get this error.
我不明白为什么我可以通过'Data Source Explorer'看到数据库,即使我使用其中列出的数据库连接配置文件作为我的配置的一部分,我仍然会收到此错误。
I also tried to create a new database profile using a manual mysql connector jar (mysql-connector-java-5.1.13-bin.jar) and same end result.
我还尝试使用手动mysql连接器jar(mysql-connector-java-5.1.13-bin.jar)创建一个新的数据库配置文件,并使用相同的最终结果。
Versions of what I have:
我拥有的版本:
Eclipse version: 3.6.0 aka Helios, Build 20100617 - 1415
MySQL: 5.1.34
Hibernate Tools (from JBoss): HibernateTools-3.3.1.v201006011046R-H111-GA
(placed into Eclipse's 'dropins' folder)
What am I doing wrong in my hibernate configuration setup?
我在hibernate配置设置中做错了什么?
Help!
帮帮我!
1 个解决方案
#1
6
Your Hibernate Console Configuration doesn't have the MySQL JDBC driver on its classpath, hence the java.lang.ClassNotFoundException:com.mysql.jdbc.Driver
. From the reference guide of the Hibernate Tools:
您的Hibernate控制台配置在其类路径上没有MySQL JDBC驱动程序,因此java.lang.ClassNotFoundException:com.mysql.jdbc.Driver。从Hibernate工具的参考指南:
3.4. Creating a Hibernate Console Configuration
...
...
alt text http://docs.jboss.org/tools/2.1.0.Beta1/hibernatetools/html_single/images/plugins/plugins_3.png
...
...
- Classpath: The classpath for loading POJO and JDBC drivers; only needed if the default classpath of the Project does not contain the required classes. Do not add Hibernate core libraries or dependencies, they are already included. If you get ClassNotFound errors then check this list for possible missing or redundant directories/jars.
- Classpath:加载POJO和JDBC驱动程序的类路径;仅在项目的默认类路径不包含所需类时才需要。不要添加Hibernate核心库或依赖项,它们已经包含在内。如果您收到ClassNotFound错误,请检查此列表以查找可能丢失或冗余的目录/ jar。
- Include default classpath from project: When enabled the project classpath will be appended to the classpath specified above
- 包含项目的默认类路径:启用后,项目类路径将附加到上面指定的类路径
Does the "associated project" have the MySQL JDBC driver declared as library? If not, then you must add it (either as a project library or in the above tab).
“关联项目”是否将MySQL JDBC驱动程序声明为库?如果没有,则必须添加它(作为项目库或在上面的选项卡中)。
#1
6
Your Hibernate Console Configuration doesn't have the MySQL JDBC driver on its classpath, hence the java.lang.ClassNotFoundException:com.mysql.jdbc.Driver
. From the reference guide of the Hibernate Tools:
您的Hibernate控制台配置在其类路径上没有MySQL JDBC驱动程序,因此java.lang.ClassNotFoundException:com.mysql.jdbc.Driver。从Hibernate工具的参考指南:
3.4. Creating a Hibernate Console Configuration
...
...
alt text http://docs.jboss.org/tools/2.1.0.Beta1/hibernatetools/html_single/images/plugins/plugins_3.png
...
...
- Classpath: The classpath for loading POJO and JDBC drivers; only needed if the default classpath of the Project does not contain the required classes. Do not add Hibernate core libraries or dependencies, they are already included. If you get ClassNotFound errors then check this list for possible missing or redundant directories/jars.
- Classpath:加载POJO和JDBC驱动程序的类路径;仅在项目的默认类路径不包含所需类时才需要。不要添加Hibernate核心库或依赖项,它们已经包含在内。如果您收到ClassNotFound错误,请检查此列表以查找可能丢失或冗余的目录/ jar。
- Include default classpath from project: When enabled the project classpath will be appended to the classpath specified above
- 包含项目的默认类路径:启用后,项目类路径将附加到上面指定的类路径
Does the "associated project" have the MySQL JDBC driver declared as library? If not, then you must add it (either as a project library or in the above tab).
“关联项目”是否将MySQL JDBC驱动程序声明为库?如果没有,则必须添加它(作为项目库或在上面的选项卡中)。