4 Replies Latest reply on Sep 26, 2013 12:36 AM by Gerry Matte

    Reverse Engineering MySQL DataBase

    Wilson Lima Newbie

      Hi Guys, well, I am not such a newbie (but not experienced either), I had great experience with JBoss Seam. Now I am getting started with JBoss Forge. I did manage to create new project. Now I am trying to do a CRUD reverse engineering in a MySQL Database but i get:

      generate-entities --schema crmadm --url jdbc:mysql://localhost:3306/crmadm --driver com.mysql.jdbc.Driver --user root --password desenv --dialect org.hibernate.dialect.MySQLDialect
      ? Enter the path in the local file system to the jar file containing the JDBC driver. [null] mysql-connector-java-5.1.6.jar
      ? In which package you'd like to generate the entities, or enter for default: [br.com.padrao.model]
      java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
      ***ERROR*** An unexpected error happened during reverse engineering.
      [crmadm] crmadm $ at java.net.URLClassLoader$1.run(URLClassLoader.java:366)

       

      But, the driver is in the correct folder, I tried the Hibernate perspective and I can see the database schema and tables in it. I have configures the driver inside Eclipe Database Connections Preferences too. I can PING on it.

      Help Please!!

        • 1. Re: Reverse Engineering MySQL DataBase
          George Gastaldi Master

          Hi Wilson,

           

          This is clearly an exception for not finding the JDBC JAR. What is the correct folder you're referring to?

           

          Best Regards,

           

          George Gastaldi

          • 2. Re: Reverse Engineering MySQL DataBase
            Wilson Lima Newbie

            Hi George,

            Whenever Forge comman-line asks me this:

            [crmadm] crmadm $ generate-entities --url jdbc:mysql://localhost:3306/crmadm --driver com.mysql.jdbc.Driver --user root --password desenv --dialect org.hibernate.dialect.MySQLDialect

            ? Enter the path in the local file system to the jar file containing the JDBC driver. [null]

             

            I have tried:

            /Users/Wilson/.m2/repository/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar

            C:\Users\Wilson\.m2\repository\mysql\mysql-connector-java\5.1.6\mysql-connector-java-5.1.6.jar

            \Users\Wilson\.m2\repository\mysql\mysql-connector-java\5.1.6\mysql-connector-java-5.1.6.jar

            And lately, I put the jar file inside the home folder of the project, and try this:

            mysql-connector-java-5.1.6.jar

             

            If I do not type in any path to the driver I get no error but just a message: Found 0 tables in datasource.

            I did try a lot of stuff, search Google for some people having the same trouble, I too am impressed why it is not working... Using Windows 8 (Portuguese). Maybe the folders´ translation is messing up... Gonna check on that..

            • 3. Re: Reverse Engineering MySQL DataBase
              Wilson Lima Newbie

              Well, do not know what the heck I did. But it worked.

              Using this: /Users/Wilson/.m2/repository/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar

              And commenting in persistence.xml <!-- <property name="hibernate.hbm2ddl.auto" value="create-drop"/> -->

              Also put the jar file inside FORGE_HOME/lib

              Sincerely I do not know why it was not working  and why it is working now. But it has generated the entities from the database.

              Anyway thanks everyone.

              • 4. Re: Reverse Engineering MySQL DataBase
                Gerry Matte Apprentice

                Your paths must contain forward slases or dual backslashes.  The first path you tried did not specify the drive and that may explain why it failed.  The second and third attempt used single backslashes which java interprets as "escaped" characters rather than path separators.  Your successful run was due to having the driver jar in Forge_Home/lib which made it accessible to forge since the driver was now on it's classpath.  I keep my current mysql driver in c:/s/drivers/mysql.jar to make it easy to type without errors.