4 Replies Latest reply on Jun 12, 2012 7:02 AM by f_marchioni

    Hibernate tools plugin

    mylos78

      Hi all !

      I'm trying to use te he hibernate tools plugin to reverse DB tables in my Project. So I have issued:

       

      $ forge install-plugin hibernate-tools

      Installation results in a BUILD SUCCESS, though with 2 warnings:

      [INFO] ------------------------------------------------------------------------

      [INFO] BUILD SUCCESS

      [INFO] ------------------------------------------------------------------------

      [INFO] Total time: 36.183s

      [INFO] Finished at: Tue Jun 05 13:29:53 CEST 2012

      [INFO] Final Memory: 13M/31M

      [INFO] ------------------------------------------------------------------------

      ***INFO*** Installing plugin artifact.

      ***WARNING*** Could not resolve dependency [org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar::1.0.0.Final]

      ***WARNING*** Could not resolve dependency [org.eclipse.jdt:org.eclipse.jdt.core:jar::3.2.0-v_671]

       

      Then, once I try to generate entities:

      [embedded-cache-quickstart] $ generate-entities

      ***ERROR*** [generate-entities] Plugin is not usable in current scope or project

       

      Any help ?? (BTW I'm using Forge 1.0.5)

      Thanks

      Mylos

       

        • 1. Re: Hibernate tools plugin
          koen.aers

          Hi Mylos,

           

          It looks like either

          1) you are not in the context of a project -> you should first create a project that will contain the generated entities

          2) persistence is not set up for the project -> you need to issue 'persistence setup...' before generating the entities

           

          The error message is not very helpful indeed... I'll do something about that.

           

          Also, you can predefine datasources using the 'datasource' plugin. This one can be used outside the context of a project. It will be helpful to later on generate your entities as you can just specify the predefined datasource so the generate-entities command does not ask you the details of the connection over and over again.

           

          I'll write up some more documentation for these plugins in the very near future.

           

          Hope this helps!

           

          Cheers,

          Koen

          • 2. Re: Hibernate tools plugin
            mylos78

            Thanks for your reply Koean,

            well I've sorted out the issue which was due to an error in my proxy configuration (which prevented the hibernate plugin to get installed correctly)

            Moving on, I've tried to reverse engineer my Oracle tables, but I've found the following error:

             

            [as7forge] as7forge $ generate-entities --table Customer --driver oracle.jdbc.driver.OracleDriver --dialect org.hibernate.dialect.Oracle9Dialect

             

            ? Specify the URL for the JDBC connection. [jdbc:h2:tcp://localhost/sakila] jdbc:oracle:thin:@localhost:1521:ORACLE

            ? Enter the user name for JDBC connection. [null] scott

            ? Enter the password for JDBC connection. ******

            ? Enter the path in the local file system to the jar file containing the JDBC driver. [null] C:\forge-distribution-1.0.5.Final\lib\ojdbc14.jar

            ? In which package you'd like to generate the entities, or enter for default: [com.sample.model]

            ***ERROR*** An unexpected error happened during reverse engineering.

            org.hibernate.cfg.JDBCBinderException: Duplicate class name 'com.sample.model.Syscatalog' generated for 'org.hibernate.mapping.Table(SYS.SYSCATALOG_)'. Same name where generated for 'org.hibernate.mapping.Table(SYS.SYSCATALOG_)'

                    at org.hibernate.cfg.JDBCBinder.createPersistentClasses(JDBCBinder.java:

            173)

                    at org.hibernate.cfg.JDBCBinder.readFromDatabase(JDBCBinder.java:94)

                    at org.hibernate.cfg.JDBCMetaDataConfiguration.readFromJDBC(JDBCMetaData

            Configuration.java:43)

                    at org.hibernate.forge.generate.GenerateEntitiesPlugin$2.run(GenerateEntitiesPlugin.java:514)

                    at org.hibernate.forge.generate.GenerateEntitiesPlugin.executeInNewUrlClassLoader(GenerateEntitiesPlugin.java:495)

                    at org.hibernate.forge.generate.GenerateEntitiesPlugin.doReverseEngineer

            ing(GenerateEntitiesPlugin.java:506)

                    at org.hibernate.forge.generate.GenerateEntitiesPlugin.generateEntities(GenerateEntitiesPlugin.java:403)

             

            I've tried also setting the --catalog and --schema option, however nothing worked for me.

            Any help ?

            Thanks

            Mylos

            • 3. Re: Hibernate tools plugin
              koen.aers

              Hi Mylos,

               

              Shame on us! :-)

               

              Apparently the filter options for tables, catalogs and schemas are never used by the plugin.

               

              I'll work on that today.

               

              Cheers,

              Koen

              • 4. Re: Hibernate tools plugin
                f_marchioni

                Hi guys,

                thanks for the great work @Forge. In case you might be interested, I've blogged about the Forge hibernate plugin here. Just one thing: I've hit a type mismatch on the Entity Primary key which is coded as Integer in Entity class and as Long in the view Bean class. Not tried on other DBs so I'm not sure if this issue is specific of MySQL.

                Keep forging :-)

                Francesco