How to create the hbm.xml files and the database creation scripts (.sql) ?

  1. The hbm.xml files
    1. What are hbm files ?

      hbm.xml files are used by hibernate for the ORM (Object Relational Mapping).

    2. How create these hbm.xml files ?

      In squale the hbm.xml files are generated by using comments (xdoclet2) put in the business objects. So don't modify directly the hbm files but the xdoclet comments in the business objects class.
      For create the hbm.xml files launch the target "java2hbm" of the ant file (build.xml in squale-core/_to-handle_). You will find all the hbm.xml file create in the directory : squale-core/target/generated-hbm.

      Be careful Xdoclet2 is inconsistent with java Enum. So you should exclude the Enum class in the java2hbm task

    3. What do of this hbm files ?

      You should :

      • Erase all files and directories in squale-core/src/main/java/ressources/mapping.
      • In squale-core/target/generated-hbm search the directory businessobject.
      • Copy all the directories under businessobject and paste them in the package : squale-core/src/main/java/ressources/mapping.

      Now squale will use this new hbm.xml files.

  2. The database creation scripts
    1. Introduction

      All the scripts which concern the database creation / modification are in the project squale-database. You have a list of script for each kind of database (Oracle, MySQL, ...)

      squale-core
        |
        |-- mysql
        |     |-- creation-scripts
        |     |     |-- 01-databaseCreation.sql
        |     |     |-- 02-setDefaultValues.sql
        |     |     `-- 03-initSquale.sql
        |     |
        |     `-- migration-scripts
        |           |-- current-migration-script.sql
        |           |-- N-1toN_script
        |           |     `-- N-1toN-migration-script.sql
        |
        |-- mysql
        |     |-- creation-scripts
        |     |     |-- 01-databaseCreation.sql
        |     |     |-- 02-setDefaultValues.sql
        |     |     `-- 03-initSquale.sql
        |     |
        |     `-- migration-scripts
        |           |-- current-migration-script.sql
        |           |-- N-1toN_script
        |           |     `-- N-1toN-migration-script.sql
      
    2. Modify the database

      If you change the hbm files the database creation script (01-databaseCreation.sql) and the current-migration-script.sql will also change.

      1. For 01-databaseCreation.sql

        For create the new script

        • In hibernate.cfg.xml (squale-web/src-main/webapp/WEB-INF/config) set the good dialect for the database :
                  For Oracle :
                  
                          <property name="dialect">org.hibernate.dialect.OracleDialect</property>
                  
                  
                  For MySQL :
                          
                          <property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
          
        • Launch the target "hbm2ddl" of the ant file (build.xml squale-core/_to-handle_)
        • The .sql file is in squale-core/target/generated-ddl.
        • Be careful This script need modifications before being used for create the database.\
          • The constraints : "on delete cascade" are not insert in the script by the ant task. You should write them yourself. For that take example on the old databaseCreation script
          • The constraint "not null" of the column applicationId of the table UserAccess should be remove. See issue [#107].

        For create the script the ant task use the hbm.xml files which are in squale-core/src/main/java/ressources/mapping. So in a same ant launch we can't create the new hbm file and the new script.

      2. For the current-migration-script.sql

        Write in this file the good sql instruction in order to pass from the old database to the new database.