Skip to main content

Dialect

Different databases have vastly different SQL support, so Jimmer uses dialect configuration to adapt to different databases.

Set Dialect

  • If using the Spring Boot Starter provided by Jimmer, there are two ways:

    • Configure application.yml or application.properties

      jimmer:
      dialect: org.babyfish.jimmer.sql.dialect.MySqlDialect
    • Provide global dialect Bean

      @Bean
      public Dialect dialect() {
      return new MySqlDialect();
      }
      info

      If both methods above are used (not recommended), the second method takes precedence

  • If not using the Spring Boot Starter provided by Jimmer

    JSqlClient sqlClient = JSqlClient
    .newBuilder()
    .setDialect(new MySqlDialect())
    ...Omit other configurations...
    .build();

Dialect List

  • org.babyfish.jimmer.sql.dialect.DefaultDialect

    This is the default dialect used by Jimmer when no dialect is specified, so there is no need to specify it explicitly.

    warning

    The default configuration can only be used for learning simple demos in the initial stage, and can never be used in actual projects. The following situations will cause exceptions:

    • Operations on Jimmer in the code will generate SQL that depends on specific database products, rather than perfect cross-database SQL

    • When the type of trigger is set to TRANSACTION_ONLY and cache is used, Jimmer will automatically create the JIMMER_TRANS_CACHE_OPERATOR table at startup. DefaultDialect does not support this operation, please refer to Cache Consistency

  • org.babyfish.jimmer.sql.dialect.H2Dialect

  • org.babyfish.jimmer.sql.dialect.MySqlDialect

  • org.babyfish.jimmer.sql.dialect.PostgresDialect

  • org.babyfish.jimmer.sql.dialect.OracleDialect

  • org.babyfish.jimmer.sql.dialect.TiDBDialect

    Because TiDB is a distributed database that does not support foreign key constraints, true foreign keys are not supported by this dialect. Please refer to True and False Foreign Keys

    Apart from this, TiDBDialect has no difference with MySqlDialect.

  • For other databases, users can extend dialects by themselves. But the database needs to support multi-column in expressions, such as

    where (a, b) in ((3, 4), (8, 13)) 

    Or

    where (a, b) in (select x, y from ...)
    note

    Currently, multi-column in expressions are highly dependent features of Jimmer, and Microsoft Sql Server does not support this feature for the time being.

    So Microsoft Sql Server is not supported for now.