2 Replies Latest reply on May 27, 2012 9:41 PM by Brad Scott

    hibernate-tools plugin not limiting to schema and table

    Brad Scott Newbie

      When generating entities for a database, I am getting the following error:

       

      Duplicate class name 'com.autotrader.forge.bo.CfContract' generated for 'org.hibernate.mapping.Table(MM_QA.CF_CONTRACT)'. Same name where generated for 'org.hibernate.mapping.Table(MM_QA.CF_CONTRACT)'

       

      Figuring there was something screwy in my database configuration, I tried to generate just one entity for one table like so:

       

      ? Table pattern to include. 'CUSTOMER' for specific table, 'CUST*' for substring match and '*' for all (the default) [PR_FEATURE]

      ? Schema pattern to include. Same syntax as for table [master] MASTER

       

      However, I get the same results.  Is there a way to generate an entity for just one table?

        • 1. Re: hibernate-tools plugin not limiting to schema and table
          Koen Aers Master

          Hi Brad,

           

          I'll take a look at this (but probably after the weekend). In the meantime, if you can post SQL for a minimal database schema as well as the Forge script that reproduces your issue that would be extremely helpful.

           

          Cheers,

          Koen

          • 2. Re: hibernate-tools plugin not limiting to schema and table
            Brad Scott Newbie

            Hi Koen.  Thanks for taking the time to respond to my question.

             

            The database I orginally had this problem on is fairly large and complicated, so I reproduced it on a more simple, h2 database.  Are you familiar with the sakila sample database from Max Anderson?  It is available at https://github.com/maxandersen/sakila-h2.

             

            Using the sakila database, I did the following in Forge:

             

            [no project] bin $ new-project --named forgesakila

            [forgesakila] forgesakila $ forge install-plugin hibernate-tools

            [forgesakila] forgesakila $ persistence setup --provider HIBERNATE --container JBOSS_AS7

            [forgesakila] forgesakila $ generate-entities configure-settings

            ? Table pattern to include. 'CUSTOMER' for specific table, 'CUST*' for substring match and '*' for all (the default) [*] COUNTRY

            ? Schema pattern to include. Same syntax as for table [*]

            ? Catalog pattern to include. Same syntax as for table [*]

            ? Package to use for generated entities. [null] com.scobra.forgesakila.bo

            ? Class name for JDBC driver [org.hsqldb.jdbcDriver] org.h2.Driver

            ? Path in the local file system to the jar file containing the JDBC driver [null] /home/brad/h2.jar

            ? URL for JDBC connection [jdbc:hsqldb:localhost:9001] jdbc:h2:tcp://localhost/sakila

            ? Username for JDBC connection [sa]

            ? Dialect to use for database [org.hibernate.dialect.HSQLDialect] org.hibernate.dialect.H2Dialect

            ? Detect many to many associations between tables. [Y/n] n

            ? Detect one-to-one associations between tables. [Y/n] n

            ? Detect optimistic locking tables, i.e. if a table has a column named 'version' with a numeric type optimistic locking will be setup for that table. [Y/n]

            [forgesakila] forgesakila $ generate-entities

            log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).

            log4j:WARN Please initialize the log4j system properly.

            log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

            Found 16 tables in datasource

            Generated java at /home/brad/forgesakila/src/main/java/com/scobra/forgesakila/bo/FilmText.java

            Generated java at /home/brad/forgesakila/src/main/java/com/scobra/forgesakila/bo/Country.java

            Generated java at /home/brad/forgesakila/src/main/java/com/scobra/forgesakila/bo/Payment.java

            Generated java at /home/brad/forgesakila/src/main/java/com/scobra/forgesakila/bo/Actor.java

            Generated java at /home/brad/forgesakila/src/main/java/com/scobra/forgesakila/bo/Customer.java

            Generated java at /home/brad/forgesakila/src/main/java/com/scobra/forgesakila/bo/Inventory.java

            Generated java at /home/brad/forgesakila/src/main/java/com/scobra/forgesakila/bo/FilmActor.java

            Generated java at /home/brad/forgesakila/src/main/java/com/scobra/forgesakila/bo/Language.java

            Generated java at /home/brad/forgesakila/src/main/java/com/scobra/forgesakila/bo/Category.java

            Generated java at /home/brad/forgesakila/src/main/java/com/scobra/forgesakila/bo/Rental.java

            Generated java at /home/brad/forgesakila/src/main/java/com/scobra/forgesakila/bo/City.java

            Generated java at /home/brad/forgesakila/src/main/java/com/scobra/forgesakila/bo/Store.java

            Generated java at /home/brad/forgesakila/src/main/java/com/scobra/forgesakila/bo/Address.java

            Generated java at /home/brad/forgesakila/src/main/java/com/scobra/forgesakila/bo/Film.java

            Generated java at /home/brad/forgesakila/src/main/java/com/scobra/forgesakila/bo/FilmCategory.java

            Generated java at /home/brad/forgesakila/src/main/java/com/scobra/forgesakila/bo/Staff.java

            Generated java at /home/brad/forgesakila/src/main/java/com/scobra/forgesakila/bo/FilmActorId.java

            Generated java at /home/brad/forgesakila/src/main/java/com/scobra/forgesakila/bo/FilmCategoryId.java 

             

            As you can see, I only wanted an entity for the COUNTRY table, but entities were generated for all tables.