Class Diagrams to Database Schemas

Bx Examples Repository

Title: ClassDiagramsToDataBaseSchemas

Version: 0.1


Industrial, Sketch.


This is a family of transformations that are all simplified variants of the class diagram to database schema transformation challenge originally posed in [0].

Currently the collection comprises four variants described below in the Variants section.
Feel free to add your own favourite variants!


Everyone roughly knows what a class diagram is and the various metamodels typically consist of concepts for Classes with Attributes, connection between Classes as Associations, and often inheritance between Classes.

Database schemas are typically simpler, consisting only of tables, entries, and a way of referencing entries in other tables via primary/foreign keys.

There are many ways of "flattening" a class diagram structure into a table structure (described in detail in the initial proposal referenced above), and the variants handle some of the different strategies.

A bit disturbing for database experts is that most variants of this transformation do not really make sense, i.e., they have been simplified beyond practical reason and only serve as interesting, but minimal examples that are not necessarily feasible or useful. Once you can accept this, however, the transformation serves as a great source for interesting non-bijective synchronization scenarios with information-loss (e.g. inheritance hierarchy) and non-deterministic choices (there can be many ways to restore consistency after perfoming changes on one side).


Please refer to the workshop paper referenced above or to the concrete variants provided here described below under Variants.

Consistency Restoration

Please refer to the workshop paper referenced above or to the concrete variants provided here described below under Variants.

Properties [optional section]

Variants [optional section]

The following variants are currently provided as TGGs (see the Artefacts section below):

  • CDToDB_1 (based on the PhD thesis of Felix Klar [1]): This variant is actually bijective. So the entire structure or the class diagram is retained in the database schema by a clever encoding of information in attribute values and by using the one class to one table mapping strategy. This variant also makes heavy use of negative application conditions to ensure that ordered attributes in classes are transformed to ordered columns in tables.
  • CDToDB_2 (based on the BX TGG tool comparison paper [2]): This is a very simple variant, chosen so that all TGG tools (known at the time the paper was written) could be compared. Many problems are avoided and the transformation is almost trivial but probably of didactic value for TGG newbies.
  • CDToDB_3 (based on the TGG paper [3]): This variant demands ordering of attributes and columns to showcase how negative application conditions can be used in TGGs to ensure such constraints. Similar to CDToDB_1 but with information loss so non-bijective.
  • CDToDB_4 (simplified version): A very simplified version of the transformation similar to CDToDB_2 but with information loss so non-bijective (not all TGG tools could handle this when the comparison paper [4] was written).
  • CDToDB_5 (based on the BX paper [4]) : This is a non-bijective variant of the transformation, in particular the scenario shows how intrinsic characteristics of bx (i.e., non-injectivity and non-totality) may cause side effects when transforming models in forward and backward directions and, especially, when propagating changes in a round-trip process. This is illustrated by means of two scenario configurations.


References [optional section]

[0] Bézivin, J., Rumpe, B., Schürr, A., Tratt, L. Model Transformations in Practice Workshop. In Bruel (ed.), MoDELS 05. Volume 3844 (January), pp. 120–127. Springer, 2006.

[1] Klar, F. (2012). Effcient and Compatible Bidirectional Formal Language Translators based on Extended Triple Graph Grammars. TU Darmstadt.

[2] Hildebrandt, S., Lambers, L., Giese, H., Rieke, J., Greenyer, J., Schäfer, W., Lauder, M., Anjorin, A., Schürr, A. (2013). A Survey of Triple Graph Grammar Tools. ECEASST, 57, 1–18.

[3] Klar, F., Lauder, M., Königs, A., Schürr, A. (2010). Extended Triple Graph Grammars with Efficient and Compatible Graph Translators. Graph Transformations and Model-Driven Engineering, 5765, 141–174.

[4] Bucaioni, A., and Eramo,R., Understanding bidirectional transformations with TGGs and JTL, Post-procs EC-EASST volume for the 2nd Int. Workshop on Bidirectional Transformations (BX 2013)


Anthony Anjorin.



Artefacts [optional section]

A virtual machine hosted on Share is available with a workspace containing both (Ecore) metamodels, the concrete example used above, and a TGG formalizing the consistency relation as a set of rules:

The case study described as the variant CDToDB_5 is available here.

Unless otherwise stated, the content of this page is licensed under GNU Free Documentation License.