Entity > Database Export (Create tables)

  1. In the Project Management > main-java click on Image not found Create tables from JPA entities.

  2. Select the desired data source at Persistence Unit.

  3. In the following wizard, select the resources folder.

Generate entire database (Create Table)

Use case:

  • There is no database available yet.

  • The database is to be deployed for the first time on a new test or production system.

    1. Set a name at DDL File, e.g. Create_CarsDB.ddl.

    2. Click Finish.
      Image not found
      Image not found

Result:

Create Table Statements - Generates database tables from entities.

Options:

  • Update Schema - Updates existing database tables, if they already exist.

  • Export to Database - Immediately executes the generated statements.

Perform only individual changes (update)

  1. Set a name at DDL File, e.g. Update_CarsDB.ddl.

  2. At Options select the option Update Schema.

  3. Click Finish.
    Image not found

Use case:

  • Updating an existing database

  • Changes to data model and database during development

  • Delivery of a database update

Result:

  • Update Schema - Generates the corresponding statements only for the changes and extensions made.

Options:

  • Export to Database - Immediately executes the generated statements. (Requires an active connection to the database)

Execute DDL scripts

  1. Set a Connect to a data source.

  2. Open the DDL file generated in Project Management > main-resources that you want to run.

  3. In the following SQL editor, specify the data source on which you want to execute the DDL script at Type, Name and Database.

  4. Right-click in the SQL Editor and select from the context menu > Execute All.
    Image not found

  • Generate and update database manually - It is helpful to manage the DDL files for all database changes in a versioned way. Example:
    Image not found

  • Automatically generate and update database - When initially starting your application in the servlet container, the database can be deployed or updated fully automatically. To do this, you only need to change the validate parameter in the persistence.xml in the following line.

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

Parameters: * validate - default value. The database schema is only validated. No changes are made to the database itself. * update - The database is updated accordingly based on the changes made to the entities. Only changes and additions are made. * create - The database is completely deployed. Already existing tables and data will be deleted. * create-drop - The database is completely deployed and completely deleted again after the session ends. This strategy is suitable for automated software tests, for example.