QVT Relations is a user friendly and compact language declaratively expressing the relations which must exist between model elements of source and target models. We will introduce the QVT 2.0 Relations language with the help of an example. In this example, we are going to express transformations between a simple UML class model and a simple relational database model, i.e. the Object/Relational mapping known from some frameworks like Hibernate. The next two figures show the SimpleUML and SimpleRDBMS MOF metamodels modeled by the medini meta modeler. We assume the reader knows how to interpret MOF Metamodels (see the medini MOF Guide).
The O/R mapping is defined with the following rules:
A UML package is mapped to a schema.
A persistent UML class is mapped to a table with a primary key inside the schema of its package.
An attribute is mapped to a column in the table of its class, whereby primitive and complex attributes are treated differently.
An association is mapped to a foreign key in the table of its source class referring to the primary key of the table representing its target class.