Configuring Round-Trip Engineering for Databases

www.altova.com Print this Topic Previous Page Up One Level Next page

Home >  UModel and Databases > Modeling Databases in UModel >

Configuring Round-Trip Engineering for Databases

Whenever you import a database into UModel as shown in Importing SQL Databases into UModel, your project becomes bound with the database, and you can synchronize elements either from the database into the model, or vice versa.

 

If you want to synchronize only from the database into the model, there is no need for any extra configuration—UModel takes care of all required mappings behind the curtains. For example, after each synchronization, new database tables will become new classes in the model, changed database column definitions will be updated in the model, and so on. All your database diagrams will also be updated automatically to reflect this.

 

However, if you make changes to the model and want to synchronize them back into the database, some additional configuration might be necessary in the UModel project. This configuration may also be necessary if you want to prevent the project (or certain tables) from synchronizing with the database.

 

A synchronization can either merge or overwrite changes—you can always configure this by running the menu command Project | Synchronization Settings.

 

Note:Some database kinds do not allow changing the database structure by virtue of their design. For example, renaming tables and columns is not supported by Microsoft Access databases. Likewise, renaming columns is not supported in SQLite. Therefore, such changes in the model will not trigger a database update, and UModel may display warnings in the Messages window.

 

Round-trip engineering for databases is very similar with round-trip engineering for program code—it revolves around a component in the "Component View" package that binds your project to the real database. Specifically, whenever you import the database for the first time, a code engineering component is generated automatically under the "Component View" package. For example, if you followed all the steps in Importing SQL Databases into UModel , then a component called um_ic_component tutorial_database was generated:

um_db_import_09

As stated before, each class in the model corresponds to a database table. For code engineering to be possible, the code engineering component must realize all the classes (tables) from the model—notice all the ComponentRealization relationships in the image above. Classes that are not realized by this component will not be part of code engineering. If you do not intend to ever update the database from the model, you do not need to take any action—UModel will create all realizations automatically whenever you synchronize from database to model.

 

However, if you intend to synchronize from the model to the database, each new class (table) that you add must have a ComponentRealization relationship to the code engineering component. Otherwise, when you attempt to update the database from the model, UModel displays a warning similar to the following: Table1 has no ComponentRealization to a component - no code will be generated.

 

The easiest way to create a ComponentRealization from a class to a component is to drag the class and drop it onto the code engineering component. So, for example, if you created a new class (table), drag the class (in the Model Tree window) onto the um_ic_component tutorial_database component to create the relationship. You can also add or remove such relationships from a Component diagram (see Component Diagrams).

 

For a worked example, see Example: Update a Database from the Model.


© 2019 Altova GmbH