13 Replies Latest reply on Jan 28, 2015 9:56 AM by Sandro Villarroel

    How to use Forge 2.10.1.Final jpa-generate-entities-from-tables ?

    Jesus Perales Newbie

      I'm using jboss developer studio 8 and trying to generate entities with forge 2.10.1.Final  and got the following error:

       

      ***ERROR*** Unable to make JDBC Connection [jdbc:mysql://localhost:3306/database]

       

      The url is the same as I have in the datasource for another project, I think I'm doing something wrong, these are the commands:

       

      project-new --named example_2

       

      jpa-setup --provider Hibernate --dbType MYSQL5 --container WILDFLY --dataSourceName java:jboss/datasources/database

       

      jpa-generate-entities-from-tables --jdbcUrl jdbc:mysql://localhost:3306/database?characterEncoding=UTF-8 --userName user --userPassword password --driverLocation /home/user/mysql-connector-java-5.1.30-bin.jar


      In my datasource I have the following:

       

      <datasource jta="true" jndi-name="java:jboss/datasources/database" pool-name="database" enabled="true" use-java-context="true" use-ccm="true">

                          <connection-url>jdbc:mysql://localhost:3306/database?characterEncoding=UTF-8</connection-url>

                          <driver>mysql-connector-java-5.1.30-bin</driver>

                          <new-connection-sql>SELECT 1</new-connection-sql>

                          <pool>

                              <min-pool-size>15</min-pool-size>

                              <max-pool-size>340</max-pool-size>

                          </pool>

                          <security>

                              <user-name>user</user-name>

                              <password>password</password>

                          </security>

                          <validation>

                              <check-valid-connection-sql>select 1</check-valid-connection-sql>

                          </validation>

                          <timeout>

                              <idle-timeout-minutes>10</idle-timeout-minutes>

                          </timeout>

        </datasource>

       

      Try downloading the zip for GNU / Linux (Fedora 20) and gave the same error.

      And even when I pass as parameter --hibernateDialect gives me the menu to choose the dialect(org.hibernate.dialect.MySQL5Dialect , option zero).

      Any ideas?

       

      Excuse my English is bad.

        • 1. Re: How to use Forge 2.10.1.Final jpa-generate-entities-from-tables ?
          Gerry Matte Apprentice

          It looks like you are trying to use a MySQL database named 'database'.  Is that truly the name of your database ?

          Did you create your database tables as InnoDB tables ?  Unless you intend to not use transactions with hibernate, you will want to use InnoDB and that changes your database type from MYSQL5 to MYSQL5_INNODB.  Your hibernate dialect also must reflect InnoDB tables.

          Finally, your datasource seems unusual: the driver element looks like part of the jar file name rather than a java class name.

           

          My examples below are using jboss 7.1.1 so the dataSource name conforms to JEE6 JNDI conventions...Wildfly may use different conventions.

          Also, my example datasource file (par-ds.xml) may require changes for Wildfly.  These steps have been tested with forge 2.10.1.Final.

           

          These are the steps I follow to generate entities for all the tables in my 'par' database:

           

          1. Create a new project named 'par':

          project-new --named par --topLevelPackage ca.gerrymatte.par --type war --finalName par ;

           

          2. Install the jpa plug-in and specify in the persistence.xml that a datasource named parDS will be available when jboss/wildfly starts the webapp:

          jpa-setup --provider Hibernate --dbType MYSQL5_INNODB --container JBOSS_AS7 --dataSourceName java:jboss/datasources/parDS;

           

          3. I choose to create a named connection so that I can be sure the database par is accessible from forge:

          connection-create-profile - --name parConnection --hibernateDialect org.hibernate.dialect.MySQL5InnoDBDialect --driverClass com.mysql.jdbc.Driver --driverLocation C:/s/jclasses/drivers/mysql.jar --userName root --userPassword xxxx --jdbcUrl jdbc:mysql:///par?characterEncoding=UTF-8&amp;characterSetResults=UTF-8&amp;autoReconnect=true&amp;zeroDateTimeBehavior=convertToNull --verifyConnection true;

           

          4. Generate JPA Entities for all tables using the connection profile:

          jpa-generate-entities-from-tables - --databaseTables * --connectionProfile parConnection --targetPackage ca.gerrymatte.par.model ;

           

           

          My par-ds.xml file contains:

          <?xml version="1.0" encoding="UTF-8"?>

          <datasources xmlns="http://www.jboss.org/ironjacamar/schema">

           

                          <datasource jta="true" jndi-name="java:jboss/datasources/parDS" pool-name="parDS" enabled="true" use-java-context="true" use-ccm="true">

                              <connection-url>jdbc:mysql:///par?characterEncoding=UTF-8&amp;characterSetResults=UTF-8&amp;autoReconnect=true&amp;zeroDateTimeBehavior=convertToNull</connection-url>

                              <driver>mysql</driver>

                              <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>

                              <pool>

                                  <min-pool-size>10</min-pool-size>

                                  <max-pool-size>20</max-pool-size>

                                  <prefill>false</prefill>

                              </pool>

                              <security>

                                  <user-name>root</user-name>

                                  <password>xxxx</password>

                              </security>

                              <statement>

                                  <prepared-statement-cache-size>20</prepared-statement-cache-size>

                                  <share-prepared-statements>true</share-prepared-statements>

                              </statement>

                          </datasource>

            

          </datasources>

          • 2. Re: How to use Forge 2.10.1.Final jpa-generate-entities-from-tables ?
            Jesus Perales Newbie

            thanks, i try again and comment.


            It looks like you are trying to use a MySQL database named 'database'.  Is that truly the name of your database ?

            Not the real name of my database.

            • 3. Re: How to use Forge 2.10.1.Final jpa-generate-entities-from-tables ?
              Bruce Link Newbie

              Tried this with forge 2.12.2.  on windows 7, java 1.7.0_45, JBOSS_HOME set to wildfly 8.1

               

              The connection-create-profile indicates that the profile is saved, but I do not find any files on the system corrsponfing to it.

              The jpa-generate-entities-from-tables fails to provide a password, so cannot login to the database.  Adding --userPassword to this command does not help.

              Following is what I tried:

               

              project-new --named tshirts --topLevelPackage ca.bcit.infosys.tshirts --type war --finalName tshirts ;

              jpa-setup --provider Hibernate --dbType MYSQL5_INNODB --container JBOSS_AS7 --dataSourceName java:jboss/datasources/tshirtsDS;

              connection-create-profile - --name tshirtsConnection --hibernateDialect org.hibernate.dialect.MySQL5InnoDBDialect --driverClass com.mysql.jdbc.Driver --driverLocation D:\Apps\mysql-connector-java-5.1.33\mysql-connector-java-5.1.33-bin.jar --userName TSHIRTS --userPassword TSHIRTS --jdbcUrl jdbc:mysql:///tshirts?characterEncoding=UTF-8&amp;characterSetResults=UTF-8&amp;autoReconnect=true&amp;zeroDateTimeBehavior=convertToNull --verifyConnection true;

              jpa-generate-entities-from-tables - --userPassword TSHIRTS --databaseTables * --connectionProfile tshirtsConnection --targetPackage ca.bcit.infosys.tshirts.model ;

              • 4. Re: How to use Forge 2.10.1.Final jpa-generate-entities-from-tables ?
                Gerry Matte Apprentice

                Your commands look ok.  Some ideas to consider:

                --driverLocation uses backslashes which may be incorrectly interpreted.  Try forward slashes instead.

                passwords are usually case sensitive.  Are you certain your userPassword should be all uppercase ?

                do not use --userPassword with the jpa-generare-entities-from-tables when using a connectionProfile

                try generating the tables without using --databaseTables * and see if you are prompted for password or table names.

                 

                Although I am not a forge expert, it is my belief that the connectionProfile only exists during the session in which it is created.

                 

                I assume you are using these commands from within a DOS Window - not from within Eclipse, right ?

                 

                Since we are almost neighbours, I'll retest my commands with 2.12.Final tomorrow and let you know the result.

                 

                You do not indicate what errors you are seeing that lead you to believe the generate entities failed....

                • 5. Re: How to use Forge 2.10.1.Final jpa-generate-entities-from-tables ?
                  Bruce Link Newbie

                  I tried with /, no difference.

                   

                  The results in the command line are:

                   

                  [Projects]$ project-new --named tshirts --topLevelPackage ca.bcit.infosys.tshirts --type war --finalName tshirts ;

                  ***SUCCESS*** Project named 'tshirts' has been created.

                  [tshirts]$ jpa-setup --provider Hibernate --dbType MYSQL5_INNODB --container JBOSS_AS7 --dataSourceName java:jboss/datasources/tshirtsDS;

                  ***SUCCESS*** Persistence (JPA) is installed.

                  [persistence.xml]$ connection-create-profile - --name tshirtsConnection --hibernateDialect org.hibernate.dialect.MySQL5InnoDBDialect --driverClass com.mysql.jdbc.Driver --driverLocation D:/Apps/mysql-

                  connector-java-5.1.33/mysql-connector-java-5.1.33-bin.jar --userName TSHIRTS --userPassword TSHIRTS --jdbcUrl jdbc:mysql:///tshirts?characterEncoding=UTF-8&amp;characterSetResults=UTF-8&amp;autoReconn

                  ect=true&amp;zeroDateTimeBehavior=convertToNull --verifyConnection true;

                  ***SUCCESS*** Connection profile tshirtsConnection has been saved successfully

                  [persistence.xml]$ jpa-generate-entities-from-tables - --userPassword TSHIRTS --databaseTables * --connectionProfile tshirtsConnection --targetPackage ca.bcit.infosys.tshirts.model ;

                  ***ERROR*** Access denied for user 'TSHIRTS'@'localhost' (using password: NO)

                  ***ERROR*** At least one database table must be specified

                   

                   

                  The password is all caps, it works from the command-line mysql client.

                   

                  I did run the above from the command prompt.  It clearly indicates it is not using the password.

                   

                  I attach file to create the database in mysql.

                  • 6. Re: Re: How to use Forge 2.10.1.Final jpa-generate-entities-from-tables ?
                    Gerry Matte Apprentice

                    Ok.  It appears that one of the recent releases undid the fixup that was implemented in 2.9.2.Final.  I have filed JIRA 2162 - see [FORGE-2162] Two previous JIRA changes have been undone FORGE-1984 and FORGE-1990 - JBoss Issue Tracker

                     

                    I repeated my commands with version 2.12.0.Final and I encountered the same errors as you did.

                    Below are the results of my forge session using the exact same statements that suceeded in version 2.10.0.Final.

                     

                    Microsoft Windows [Version 6.1.7601]

                    Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

                     

                    C:\Users\Gerry\Documents\$develop\$code>forge

                     

                        _____

                      |  ___|__  _ __ __ _  ___

                      | |_ / _ \| `__/ _` |/ _ \  \\

                      |  _| (_) | | | (_| |  __/  //

                      |_|  \___/|_|  \__, |\___|

                                      |__/

                     

                     

                    JBoss Forge, version [ 2.12.0.Final ] - JBoss, by Red Hat, Inc. [ http://forge.jboss.org ]

                     

                    [$code]$ project-new --named par --topLevelPackage ca.gerrymatte.par --type war --finalName par ;

                    ***SUCCESS*** Project named 'par' has been created.

                    [par]$ jpa-setup --provider Hibernate --dbType MYSQL5_INNODB --container JBOSS_AS7 --dataSourceName java:jboss/datasources/parDS;

                    ***SUCCESS*** Persistence (JPA) is installed.

                    [persistence.xml]$ connection-create-profile - --name parConnection --hibernateDialect org.hibernate.dialect.MySQL5InnoDBDialect --driverClass com.mysql.jdbc.Driver --driverLocation C:/s/jclasses/drivers/mysql.jar --userName root --userPassword xxxxxx --jdbcUrl jdbc:mysql:///par?characterEncoding=UTF-8&amp;characterSetResults=UTF-8&amp;autoReconnect=true&amp;zeroDateTimeBehavior=convertToNull --verifyConnection true;

                    ***SUCCESS*** Connection profile parConnection has been saved successfully

                    [persistence.xml]$ jpa-generate-entities-from-tables - --databaseTables * --connectionProfile parConnection --targetPackage ca.gerrymatte.par.model ;

                    ***ERROR*** Access denied for user 'root'@'localhost' (using password: NO)

                    ***ERROR*** At least one database table must be specified

                    [persistence.xml]$

                    ;

                     

                    ==== Second test ==============================================================================================================

                    Oddly, when I tested again using the most recent production version 2.12.3.Final, I discovered that the message that a Connection profile has been saved no longer appears and the same errors occur when attempting to generate entities from tables:

                    Microsoft Windows [Version 6.1.7601]

                    Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

                     

                    C:\Users\Gerry\Documents\$develop\$code>forge

                     

                        _____

                      |  ___|__  _ __ __ _  ___

                      | |_ / _ \| `__/ _` |/ _ \  \\

                      |  _| (_) | | | (_| |  __/  //

                      |_|  \___/|_|  \__, |\___|

                                      |__/

                     

                    JBoss Forge, version [ 2.12.3.Final ] - JBoss, by Red Hat, Inc. [ http://forge.jboss.org ]

                     

                    [$code]$ project-new --named par --topLevelPackage ca.gerrymatte.par --type war --finalName par ;

                    ***SUCCESS*** Project named 'par' has been created.

                    [par]$ jpa-setup --provider Hibernate --dbType MYSQL5_INNODB --container JBOSS_AS7 --dataSourceName java:jboss/datasources/parDS;

                    ***SUCCESS*** Persistence (JPA) is installed.

                    [persistence.xml]$ [persistence.xml]$ connection-create-profile - --name parConnection --hibernateDialect org.hibernate.dialect.MySQL5InnoDBDialect --driverClass com.mysql.jdbc.Driver --driv

                    erLocation C:/s/jclasses/drivers/mysql.jar --userName root --userPassword xxxxxx --jdbcUrl jdbc:mysql:///par?characterEncoding=UTF-8&amp;characterSetResults=UTF-8&amp;autoReconnect=true&amp;

                    zeroDateTimeBehavior=convertToNull --verifyConnection true;

                    [persistence.xml]$ jpa-generate-entities-from-tables - --databaseTables * --connectionProfile parConnection --targetPackage ca.gerrymatte.par.model ;

                    ***ERROR*** Access denied for user 'root'@'localhost' (using password: NO)

                    ***ERROR*** At least one database table must be specified

                    [persistence.xml]$

                    • 7. Re: Re: Re: How to use Forge 2.10.1.Final jpa-generate-entities-from-tables ?
                      Gerry Matte Apprentice

                      Just to verify that the forge commands have broken after version 2.10.1.Final, I reverted my forge to that version and repeated my test:

                      Microsoft Windows [Version 6.1.7601]

                      Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

                       

                      C:\Users\Gerry\Documents\$develop\$code>forge

                       

                          _____

                        |  ___|__  _ __ __ _  ___

                        | |_ / _ \| `__/ _` |/ _ \  \\

                        |  _| (_) | | | (_| |  __/  //

                        |_|  \___/|_|  \__, |\___|

                                        |___/

                       

                      JBoss Forge, version [ 2.10.1.Final ] - JBoss, by Red Hat, Inc. [ http://forge.jboss.org ]

                       

                      [$code]$ project-new --named par --topLevelPackage ca.gerrymatte.par --type war --finalName par ;

                      ***SUCCESS*** Project named 'par' has been created.

                      [par]$ jpa-setup --provider Hibernate --dbType MYSQL5_INNODB --container JBOSS_AS7 --dataSourceName java:jboss/datasources/parDS;

                      ***SUCCESS*** Persistence (JPA) is installed.

                      [persistence.xml]$ connection-create-profile - --name parConnection --hibernateDialect org.hibernate.dialect.MySQL5InnoDBDialect --driverClass com.mysql.jdbc.Driver --driverLocation C:/s/jcl

                      asses/drivers/mysql.jar --userName root --userPassword xxxxxx --jdbcUrl jdbc:mysql:///par?characterEncoding=UTF-8&amp;characterSetResults=UTF-8&amp;autoReconnect=true&amp;zeroDateTimeBehavio

                      r=convertToNull --verifyConnection true;

                      ***SUCCESS*** Connection profile parConnection has been saved successfully

                      [persistence.xml]$ jpa-generate-entities-from-tables - --databaseTables * --connectionProfile parConnection --targetPackage ca.gerrymatte.par.model ;

                      ***SUCCESS*** 11 entities were generated in ca.gerrymatte.par.model

                      [persistence.xml]$

                      • 9. Re: Re: How to use Forge 2.10.1.Final jpa-generate-entities-from-tables ?
                        George Gastaldi Master

                        Just a minor correction to your command. There was a dash between the command name and the --name parameter and --verifyConnection doesn't work with true next to it - the correct usage is to not specify anything and if you want to force it to be false, use --verifyConnection=false:

                         

                        connection-create-profile --name parConnection --hibernateDialect org.hibernate.dialect.MySQL5InnoDBDialect --driverClass com.mysql.jdbc.Driver --driverLocation C:/s/jclasses/drivers/mysql.jar --userName root --userPassword xxxxxx --jdbcUrl jdbc:mysql:///par?characterEncoding=UTF-8&amp;characterSetResults=UTF-8&amp;autoReconnect=true&amp;zeroDateTimeBehavior=convertToNull --verifyConnection;

                         

                        I am investigating what is causing this.

                        Thanks for reporting it!

                        • 10. Re: Re: How to use Forge 2.10.1.Final jpa-generate-entities-from-tables ?
                          Gerry Matte Apprentice

                          Thanks George for the corrections to my commands.

                          The extra dash after the command name was also present with the jpa-generate-entities-from-tables command.

                          • 11. Re: Re: How to use Forge 2.10.1.Final jpa-generate-entities-from-tables ?
                            George Gastaldi Master

                            Bruce,

                             

                            The option name for the connection profile password is --connectionProfilePassword, not --userPassword as in your example

                             

                            Gerry,

                            to save the password, you MUST specify --saveUserPassword when creating the profile, otherwise the password will NOT be saved. It looks like this broke compatibility with older versions, but it should work.

                            • 12. Re: Re: How to use Forge 2.10.1.Final jpa-generate-entities-from-tables ?
                              Gerry Matte Apprentice

                              These two changes did not correct the problem.  I re-opened the JIRA.as requested.

                              • 13. Re: How to use Forge 2.10.1.Final jpa-generate-entities-from-tables ?
                                Sandro Villarroel Newbie

                                This works for me

                                 

                                1) jpa-setup --provider Hibernate --container JOSS_AS7 --dbType MYSQL --dataSourceName java:jboss/datasources/facturacionDS;

                                 

                                2) connection-create-profile --name coneFact --hibernateDialect org.hibernate.dialect.MySQL5Dialect --driverClass com.mysql.jdbc.Driver --driverLocation D:\conectores_odbc\mysql-connector-java-5.1.7-bin.jar --userName root --userPassword root --jdbcUrl jdbc:mysql://localhost:3306/facturacion  --saveUserPassword Y;

                                 

                                3) jpa-generate-entities-from-tables --connectionProfile coneFact --targetPackage src.main.java --databaseTables * ;