How to define custom database type for column before generating Liquibase changeset


I create new Entity, then start Application. On start Jmix detects that there is no table in database for my new Entity and generate xml Liquibase changeset for creating it. But in this generated xml there are wrong datatypes. For example, I want to use NVARCHAR instead of VARCHAR or DATETIME2 instead of DATETIME in MSSQL database.

For now I need to review and manually replace generated types before starting Application.
Is there any opportunity to configure Jmix datatype generation mapping for different databases (defined by Liquibase’s “dbms” attribute)?

Liquibase itself has some functionality for this purpose
but it seems JMIX must generate types like ${datatype_property_name} for using it.

Thanks for your feedback!

There is no such option to change generation mapping project-wide.
You can use columnDefinition attribute of the @Column annotation to specify custom SQL type where it is needed. (Column definition field in entity designer). E.g.:

    @Column(name = "TEST", columnDefinition = "nvarchar")
    private String test;

Another option is to create custom datatype and use it instead of basic datatype provided by Jmix Framework.
E.g. you create custom foo_string datatype and specify desired SQL type in @Ddl annotation. You can have several @Ddl annotations for each dbms type:


import io.jmix.core.metamodel.annotation.DatatypeDef;
import io.jmix.core.metamodel.annotation.Ddl;
import io.jmix.core.metamodel.datatype.impl.StringDatatype;

@DatatypeDef(id = "foo_string", javaClass = String.class)
public class FooStringDatatype extends StringDatatype {

Then use this datatype for your attributes: Select Foo_string in the Type field. PropertyDatatype annotation will be added:

    @Column(name = "TEST")
    private String test;