开发者

Hibernate Reverse Engineering with Eclipse and MySql

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 aft开发者_高级运维er creating Hibernate Console and Configuration files, I get the error:

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

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.

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.

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.

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?

Help!


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:

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜