7 Replies Latest reply on Jul 7, 2007 1:17 PM by Georges Berscheid

    Automatic table creation

    Georges Berscheid Newbie

      Hi,

      I'm deploying a bunch of entity beans on my JBAS 4.2.0 with my datasource pointing to a MySQL InnoDB database with no tables.
      The first time I deploy the beans, everything works fine, the tables are created and the foreign keys are defined.
      If I undeploy and redeploy the application, I get odd warnings and errors:

      11:00:14,688 INFO [InjectedDataSourceConnectionProvider] Using provided datasource
      11:00:14,898 INFO [SettingsFactory] RDBMS: MySQL, version: 5.0.32-Debian_7etch1-log
      11:00:14,898 INFO [SettingsFactory] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.11 ( $Date: 2005-09-21 18:20:03 +0000 (Wed, 21 Sep 2005) $, $Revision: 4287 $ )
      11:00:14,918 INFO [Dialect] Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
      11:00:16,381 INFO [DatabaseMetadata] table not found: accounts
      11:00:16,391 INFO [DatabaseMetadata] table not found: customers
      11:00:16,441 ERROR [SchemaUpdate] Unsuccessful: create table accounts (account_id integer not null auto_increment, name varchar(255), customer_id integer, primary key (account_id)) type=InnoDB
      11:00:16,441 ERROR [SchemaUpdate] Table 'accounts' already exists
      11:00:16,461 ERROR [SchemaUpdate] Unsuccessful: create table customers (id integer not null auto_increment, name varchar(255), billing_cycle varchar(255), city varchar(255), customer varchar(255), invoice_id varchar(255), street varchar(255), vat_no varchar(255), zip varchar(255), country_id integer, primary key (id)) type=InnoDB
      11:00:16,461 ERROR [SchemaUpdate] Table 'customers' already exists
      


      Does anybody know why it doesn't see that the tables are already there until the table creation fails?

      Thanks,
      Georges

        • 1. Re: Automatic table creation
          wayne baylor Apprentice

          what's hibernate.hbm2ddl.auto set to?

          you could also check jboss/server/default/log/server.txt
          which may have more info about the errors.

          • 2. Re: Automatic table creation
            Georges Berscheid Newbie

            Hi,

            thanks for you reply.

            <property name="hibernate.hbm2ddl.auto" value="update" />


            All it says in addition to the above is the following:
            16:12:18,321 INFO [Ejb3Configuration] found EJB3 Entity bean: eu.mpulse.commons.repository.customers.Account
            16:12:18,331 INFO [Ejb3Configuration] found EJB3 Entity bean: eu.mpulse.commons.repository.customers.Customer
            16:12:18,712 INFO [AnnotationBinder] Binding entity from annotated class: eu.mpulse.commons.repository.customers.Account
            16:12:18,712 INFO [EntityBinder] Bind entity eu.mpulse.commons.repository.customers.Account on table accounts
            16:12:18,672 INFO [AnnotationBinder] Binding entity from annotated class: eu.mpulse.commons.repository.customers.Customer
            16:12:18,672 INFO [EntityBinder] Bind entity eu.mpulse.commons.repository.customers.Customer on table customers
            16:12:21,236 ERROR [SchemaUpdate] Unsuccessful: alter table accounts add index FK809DBBE624CB3F8D (customer_id), add constraint FK809DBBE624CB3F8D foreign key (customer_id) references customers (id)
            16:12:21,236 ERROR [SchemaUpdate] Duplicate key name 'FK809DBBE624CB3F8D'


            but those messages all seem related to the original problem to me.

            Thanks,
            Georges

            • 3. Re: Automatic table creation
              wayne baylor Apprentice

              Hibernate has this info about the update setting

              Creates the database schema on deploy if it doesn't exist. Alters it if it has changed. Useful for when you want to generate database schema from entity beans


              The errors you're getting are because the schema and constraints already exist. Are you using Hibernate to generate the schema or did you do it manually?

              • 4. Re: Automatic table creation
                Georges Berscheid Newbie

                Right, that's the theory. The database was empty at first. The tables were created the first time I deployed the beans.

                If I change the entity beans, the tables are not modified at redeployment. SQL Exceptions are thrown instead when the data is accessed because the schema doesn't match. But that doesn't matter because I don't change my beans.

                I'm just wondering why it says that the tables do not exist if it has just created them in the previous deployment.

                • 5. Re: Automatic table creation
                  wayne baylor Apprentice

                  yeah, I've only seen those errors when using create-drop and it can't drop the tables because they don't exist. But that's not a fatal error and things still work...

                  • 6. Re: Automatic table creation
                    fhh Expert

                    Can the database user "see" those tables, e.g. get meta data about them?

                    Regards

                    Felix

                    • 7. Re: Automatic table creation
                      Georges Berscheid Newbie

                      The MySQL user has 'all privileges' on the database. In the previous deployment that same user was able to create the tables that he can't find in the second deployment of the entity beans.