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
orapplication.properties
jimmer:
dialect: org.babyfish.jimmer.sql.dialect.MySqlDialect -
Provide global dialect Bean
- Java
- Kotlin
@Bean
public Dialect dialect() {
return new MySqlDialect();
}@Bean
fun dialect(): Dialect =
MySqlDialect()infoIf both methods above are used (not recommended), the second method takes precedence
-
-
If not using the Spring Boot Starter provided by Jimmer
- Java
- Kotlin
JSqlClient sqlClient = JSqlClient
.newBuilder()
.setDialect(new MySqlDialect())
...Omit other configurations...
.build();val sqlClient = newKSqlClient {
setDialect(MySqlDialect())
...Omit other configurations...
}
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.
warningThe 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 theJIMMER_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 withMySqlDialect
. -
For other databases, users can extend dialects by themselves. But the database needs to support multi-column
in
expressions, such aswhere (a, b) in ((3, 4), (8, 13))
Or
where (a, b) in (select x, y from ...)
noteCurrently, 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.