1 Reply Latest reply on Aug 11, 2011 1:24 PM by Mitesh pandey

    Persistence provider creating new table even with update option

    Mitesh pandey Newbie

      Hi All,


      I am using hibernate as my persistence provider and postgre as my DB.


      My persistence.xml looks like below


      <persistence-unit name="titan" transaction-type="JTA">







                          <property name="hibernate.dialect" value=  "org.hibernate.dialect.PostgreSQLDialect" />

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

                           <property name="hibernate.show_sql" value="true" />

                           <property name="hibernate.format_sql" value="false" />

                           <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>

                           <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/Entity"/>

                           <property name="hibernate.connection.username" value="*****"/>

                           <property name="hibernate.connection.password" value="****"/>




      I have table Cabin, Customer and Address under my table Entity. When i deploy my jar and start the server , again a new table is created  as cabin, customer and address. I thought with value = "update"  for  hibernate.hbm2ddl.auto, it should not create any table and should only update the data.


      When i deleted the table from DB, then there was no table found message when the jboss is up. I don't want to duplicate the tables.


      What could be the issue ?

        • 1. Re: Persistence provider creating new table even with update option
          Mitesh pandey Newbie

          Hi All,


          On running jboss server i have a message




          [AnnotationBinder] Binding entity from annotated class: com.domain.Cabin

          [EntityBinder] Bind entity com.domain.Cabin on table Cabin

          [AnnotationBinder] Binding entity from annotated class: com.domain.Address

          [EntityBinder] Bind entity com.domain.Address on table Address

          [AnnotationBinder] Binding entity from annotated class: com.domain.Customer

          [EntityBinder] Bind entity com.domain.Customer on table Customer



          [SchemaUpdate] Running hbm2ddl schema update

            [SchemaUpdate] fetching database metadata

            [SchemaUpdate] updating schema

            [TableMetadata] table found: public.address

            [TableMetadata] columns: [zip, address_id, street, state, city]

          [TableMetadata] foreign keys: []

            [TableMetadata] indexes: [address_pkey]

          [TableMetadata] table found: public.cabin

            [TableMetadata] columns: [id, ship_id, bed_count, name, deck_level]

          [TableMetadata] foreign keys: []

            [TableMetadata] indexes: [cabin_pkey]

            [TableMetadata] table found: public.customer

            [TableMetadata] foreign keys: [fk27fbe3fe861439fd]

            [TableMetadata] indexes: [customer_pkey]

            [SchemaUpdate] schema update complete


          I googled and learnt that the update option basically update the DB schema. At one place it is binding my entity classes with the table in my DB and then while updating schema it has created new table.


          And when i tried running the test application by commenting

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


          my jboss was up with entity binding successfull but updation failed with below error


          org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update which was expected.


          I m clueless.