9 Replies Latest reply on Apr 25, 2013 6:38 AM by Max Rydahl Andersen

    JPA reverse engineer & MySQL

    Eric J. Van der Velden Newbie

      Hello,

       

      When I use JPA Tools to reverse engineer  tables in a MySQL database, called sample2 here, I get for table F:

       

      Entity

      @Table(name = "F", catalog= "sample2")

      public class F implements java.io.Serializable {

      ...

       

      But if there is a database connection (which you give when you right click on your entry in the 'Database Connections' view, for example), so that validation is on, this is not validated; I get

       

      catalog "sample2" cannot be resolved for table "F"

       

      But when I change "catalog" to "schema" then it is validated. So this is OK:  

       

      Entity

      @Table(name = "F", schema= "sample2")

      public class F implements java.io.Serializable {

      ...

       

      So is reverse engineering in case of MySQL going OK by JPA Tools, or am I doing something wrong? I use the JBoss Tools 3.2 stable.

       

      Thanks,

       

      Eric J.

        • 1. JPA reverse engineer & MySQL
          Max Rydahl Andersen Master

          hmm - sounds like a bug in mysql reverse engineering....

           

          Might be related to https://issues.jboss.org/browse/JBIDE-7488 fix

           

          Workaround set hibernate.default_catalog="sample2" and you should not get any mentions of catalog in your reverse engineering.

          • 2. Re: JPA reverse engineer & MySQL
            Dmitry Geraskov Newbie

            Eric J. Van der Velden,

            could you please check the validation with @Table(name = "F", schema= "sample2", catalog= "sample2")

            I guess hibernate tool doesn't add schema as consider it as default.

            (In url you have something jdbc:mysql://localhost:3306/?nullCatalogMeansCurrent=false)

            where mymysql is schema and you don't need to override it.

            Does hibernate work with generated annotation:

            @Table(name = "F", catalog= "sample2")

            or with updated

            @Table(name = "F", schema= "sample2")?

            Please check also

            @Table(name = "F", schema= "sample2", catalog= "sample2")

            • 3. Re: JPA reverse engineer & MySQL
              Dmitry Geraskov Newbie

              I ask this because it could be a problem of the validator, but not hibernate tools.

              • 4. Re: JPA reverse engineer & MySQL
                Dmitry Geraskov Newbie

                Eric,

                we checked this ourself. The hibernate works well with @Table(name = "F", catalog= "sample2") and one of the folowwing:

                 

                1) jdbc:mysql://localhost:3306/?nullCatalogMeansCurrent=false

                2) jdbc:mysql://localhost:3306/sample2

                3) jdbc:mysql://localhost:3306/ hibernate.default_catalog=sample2

                 

                 

                sample2

                @Table(name = "F", schema= "sample2") works in the cases:

                 

                1) jdbc:mysql://localhost:3306/?nullCatalogMeansCurrent=false

                2) jdbc:mysql://localhost:3306/sample2

                3) jdbc:mysql://localhost:3306/ hibernate.default_schema=sample2

                 

                The jpa validator is not consistent in some cases

                • 5. Re: JPA reverse engineer & MySQL
                  reskejal Newbie

                  Any news about this topic??

                  I have the same problem with stable release of jboss developer studio (6.0).

                  In my case the error is only for the validator because i can use the genereted class without problem.

                  i'm also able to fix the error but i need remove manually the catalog definition and have an annotation like this

                  @Table(name = "F")

                  and default values (in JPA property windows) are "Default" for catalog and "Default (sample2)" for schema

                  Also with this fix my project work.

                   

                  In jboss dev studio i have a Database Connection like jdbc:mysql://localhost:3306/sample2

                  while on AS and in persistence.xml use data source with jta  (connection string is always like jdbc:mysql://localhost:3306/sample2)

                   

                  Is there a way to not generate the catalog attribute in annotation ??

                   

                  Thanks.

                  • 6. Re: JPA reverse engineer & MySQL
                    Gerry Matte Apprentice

                    This behavior has been standard for MySQL and hibernate from the beginning.    I belive the MySQL driver interprets a database schema the same as an Oracle catalog .... but a MySQL catalog has subtle differences from a schema and does not play well with hibernate. 

                     

                    My standard fix up (workaround) is to immediately remove the catalog property.  I most frequently use Forge to reverse engineer and generate a CRUD webapp ..... so it's become routine for me.  Thanks to Eric for reporting the issue .... I should have done so long ago.

                    • 7. Re: JPA reverse engineer & MySQL
                      Max Rydahl Andersen Master

                      set hibernate.default_catalog and hibernate.default_schema and the reverse engineering will obey that and remove it.

                       

                      If someone know of a way to reliably know from a jdbc connection which schema/catalog is the default then we could avoid this, but I haven't found a way that is sane.

                      • 8. Re: JPA reverse engineer & MySQL
                        reskejal Newbie

                        Thanks for yours suggestions!

                        @Gerry many thanks...Forge its a great project.

                        @Max i try to set these properties in persistence.xml and in the optional parameters of the database connection..but with no luck, i have always the catalog annotation

                        • 9. Re: JPA reverse engineer & MySQL
                          Max Rydahl Andersen Master

                          hmm - it should just work.

                           

                          Can you show me the generated code and the persistence.xml you are using ?