Concepts
This section explains the main concepts behind Dynamic Model: the kinds of entities involved, how the model is defined and versioned, how changes are applied at runtime, where the data is stored, and which databases are supported.
Static and Dynamic Entities
Dynamic Model distinguishes two kinds of entities:
-
Static entities are the regular entities of your application. They are compiled into Java classes and available on the classpath.
-
Dynamic entities are defined at runtime in the model and generated by the framework. They do not exist in the application source code.
Dynamic attributes can be added to both static and dynamic entities. This means you can enrich existing application entities with new attributes and, independently, introduce completely new entities that exist only in the runtime model.
Model Definition
The dynamic model is a declarative description of enumerations, entities, attributes, and views. You edit it graphically in the admin UI: you create entities, add attributes with their types and constraints, define enumerations, and declare views and menu items.
Behind the scenes, the model is serialized as YAML. You normally work with the graphical editor and do not edit the YAML directly, but the YAML form is useful for review, export, and import. For the full list of elements, supported values, and defaults, see YAML Reference.
Versioning and Deployment
The model definition is stored in the database as a set of versioned configurations. Each apply saves a new version, and only one version is active at a time. Previous versions are kept, and you can see them in the model history. To return to an earlier model, copy its YAML from the history and apply it again.
On application startup, the framework can automatically apply the active version so that the running application reflects the latest deployed model. This behavior is controlled by the jmix.dynmodel.deploy-on-app-start property.
Applying Changes
When you apply the model, the framework builds a new metadata generation from the model definition and publishes it atomically. Until the new generation is fully prepared, the running application keeps using the previous one, so a failed apply never exposes a partially applied model.
Destructive cleanup — such as dropping columns or tables that are no longer part of the model — is deferred until the previous generation is no longer used by in-flight work. This keeps running operations consistent while the model changes.
Already open views are not switched over automatically; they pick up the changes after a reload.
The framework also checks that nobody applied another model after you opened the model for editing. If someone did, your apply is refused, so that it does not silently discard the other changes. In this case, reload the model settings and repeat your changes.
Cluster
Since Jmix 3.1
Dynamic Model can work in an application cluster. When cluster support is enabled:
-
A model applied on one node is applied on all other nodes, without a restart.
-
Only one apply can run at a time in the whole cluster. If a user tries to apply the model while it is being applied on another node, the apply is refused with a message that names the user who is applying it. Try again after the other apply is finished.
To enable cluster support:
-
Set the jmix.dynmodel.cluster.enabled property to
true. -
Add the Pessimistic Lock add-on to the project. It holds the apply lock for the cluster. If cluster support is enabled and the add-on is missing, the application does not start.
-
Configure cluster communication between the nodes as described in Cluster Communication. Both the messages about applied models and the apply lock need it. Without it, a model applied on one node reaches the other nodes only when they restart.
The jmix.dynmodel.cluster.apply-lock-timeout-sec property sets when the lock left by a node that stopped during an apply expires. Set it to a value greater than the longest apply in your application.
Storage
Dynamic Model keeps the runtime data in dedicated database tables:
-
Dynamic attributes of static entities are stored in separate side tables. By default, their names use the
DYN_prefix. A side table is created in the same physical data store as its owning static entity. -
Dynamic entities get their own dedicated tables, also using the
DYN_prefix by default, with the primary key columnDYNMOD_ID.
Each entity can specify a physical store through its store property; when omitted, the entity uses the main data store. References and collections are allowed only between entities that belong to the same physical store.
The table-name prefixes are configurable; see YAML Reference and Application Properties for the relevant settings.
Data Tools
Since Jmix 3.1
Dynamic entities and dynamic attributes are shown in the views of the Data Tools add-on:
-
The Data model view lists dynamic entities with their data store and table, and dynamic attributes of static entities with their side table columns. Calculated and collection attributes are listed without a column. The diagram shows which entities and attributes are dynamic.
-
The Entity inspector lets you browse, create, edit and delete instances of dynamic entities, and edit dynamic attributes of static entities. You can filter and sort by dynamic attributes in the generic filter.
Supported Databases
Dynamic Model supports the following databases:
-
HSQLDB
-
H2
-
PostgreSQL
-
MySQL 8+
-
MariaDB 10+
-
MS SQL Server 2012+
-
Oracle 12.2+