Version 6

    Just as you can have JBoss create the database structure, you can also have automatic updates of this database structure. This even includes automatic creation of indexes.

     

    In jbosscmp-jdbc.xml you can tell JBoss to alter the table structure if necessary. This is done using the following sections (other tags be added as needed)

     

    <defaults>
        <create-table>true</create-table>
        <alter-table>true</alter-table>
    </defaults>
    

     

    Note that you need the combination of create-table and alter-table to make sure that both added/altered fields are updated and new (link) tables are being created.

     

    This will have the following effect :

    • new fields are created

    • fields which are no longer used are removed

    • string fields which are shorter than the declared length will have their length increased to the declared length (this is not supported by all databases).

     

    Note that alter-table does not change the type of a column.

     

    All work done by alter-table is logged at WARN level.

     

    -


     

    There are variations in the SQL statements which need to be used for the alter table statements. Therefor this can be defined as part of the database specific type-mapping (in conf/standardjboss-cmp.xml). For example, these are the default templates, which are (amongst others) suitable for the Firebird database.

     

    <add-column-template>ALTER TABLE ?1 ADD ?2 ?3</add-column-template>
    <alter-column-template>ALTER TABLE ?1 ALTER ?2 TYPE ?3</alter-column-template>
    <drop-column-template>ALTER TABLE ?1 DROP ?2</drop-column-template>
    

     

    • add-column-template has the following parameters

      1. Table name

      2. Column name

      3. Column type

     

    • alter-column-template has the following parameters

      1. Table name

      2. Column name

      3. Column type

     

    • drop-column-template has the following parameters

      1. Table name

      2. Column name

     

    The SQL statements are configurable since 3.2.6RC1

     

    There's a patch on http://jira.jboss.com/jira/browse/JBAS-1366 that solves the 'duplicate column' error while checking the differences between the entity bean and the table in the database.

     

    Referenced by: