我正在尝试生成一个Liquibase diffChangeLog 正在获取:
Unexpected error running Liquibase: org.hibernate.MappingException: No Dialect mapping for JDBC type: 2003
问题似乎是在实体中使用数组属性。
我为此数组创建了一个休眠用户类型,因为休眠不支持数据库数组。
任何人都可以帮助运行 diffChangeLog 吗?
不知道我是否必须以任何方式配置liquibase或休眠...
(注意:Liquibase命令 generateChangeLog 运行成功)
(注2:在应用程序中读写数据库工作正常)
实体(科林)
import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.Table
import org.hibernate.annotations.Type
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.databind.annotation.JsonSerialize
@Entity
@Table(name = "my_entity")
class MyEntity : Serializable {
…
@Column(name = "my_values")
@JsonDeserialize(using = StringArrayDeserializer::class)
@JsonSerialize(using = StringArraySerializer::class)
@Type(type = "de.mycompany.mypackage.domain.json.CustomArrayType")
var myValues: Array<String>? = null
…
}
用户类型(java)
import java.sql.Array;
public class CustomArrayType implements UserType {
public int[] sqlTypes() {
return new int[]{Types.ARRAY};
}
public Class returnedClass() {
return String[].class;
}
…
}
具有自定义数组的实体的库更改集
<changeSet id="123456789-1" author="me">
<createTable tableName="my_entity">
…
<column name="myValues" type="varchar() []">
<constraints nullable="true" />
</column>
…
</createTable>
</changeSet>
通过gradle任务从命令行启动进程
gradle任务
def liquibaseCommand(command) {
javaexec {
main = "liquibase.integration.commandline.Main"
def cfg = <load config from yml>
args "--changeLogFile=src/main/resources/config/liquibase/changelog/" + buildTimestamp() +"_changelog.xml"
args "--referenceUrl=hibernate:spring:de.mycompany.mypackage.domain?dialect=org.hibernate.dialect.PostgreSQL95Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy"
args "--username=${cfg.spring.datasource.username}"
args "--password=${cfg.spring.datasource.password}"
args "--url=${cfg.spring.datasource.url}"
args "--driver=org.postgresql.Driver"
args command
}
}
运行产生以下错误:
错误消息
[system.err] Unexpected error running Liquibase: org.hibernate.MappingException: No Dialect mapping for JDBC type: 2003
[system.err]
system.out] [main] ERROR liquibase - org.hibernate.MappingException: No Dialect mapping for JDBC type: 2003
[system.err]
[system.out] liquibase.exception.LiquibaseException: liquibase.command.CommandExecutionException: org.hibernate.MappingException: No Dialect mapping for JDBC type: 2003
[system.out] at liquibase.integration.commandline.CommandLineUtils.doDiffToChangeLog(CommandLineUtils.java:218)
[system.out] at liquibase.integration.commandline.Main.doMigration(Main.java:996)
[system.out] at liquibase.integration.commandline.Main.run(Main.java:188)
[system.out] at liquibase.integration.commandline.Main.main(Main.java:103)
[system.out] Caused by: liquibase.command.CommandExecutionException: org.hibernate.MappingException: No Dialect mapping for JDBC type: 2003
[system.out] at liquibase.command.AbstractCommand.execute(AbstractCommand.java:13)
[system.out] at liquibase.integration.commandline.CommandLineUtils.doDiffToChangeLog(CommandLineUtils.java:216)
[system.out] ... 3 common frames omitted
[system.out] Caused by: org.hibernate.MappingException: No Dialect mapping for JDBC type: 2003
[system.out] at org.hibernate.dialect.TypeNames.get(TypeNames.java:70)
[system.out] at org.hibernate.dialect.TypeNames.get(TypeNames.java:101)
[system.out] at org.hibernate.dialect.Dialect.getTypeName(Dialect.java:346)
[system.out] at org.hibernate.mapping.Column.getSqlType(Column.java:231)
[system.out] at liquibase.ext.hibernate.snapshot.ColumnSnapshotGenerator.snapshotColumn(ColumnSnapshotGenerator.java:104)
[system.out] at liquibase.ext.hibernate.snapshot.ColumnSnapshotGenerator.addTo(ColumnSnapshotGenerator.java:78)
[system.out] at liquibase.ext.hibernate.snapshot.HibernateSnapshotGenerator.snapshot(HibernateSnapshotGenerator.java:84)
[system.out] at liquibase.snapshot.SnapshotGeneratorChain.snapshot(SnapshotGeneratorChain.java:50)
[system.out] at liquibase.snapshot.DatabaseSnapshot.include(DatabaseSnapshot.java:246)
[system.out] at liquibase.snapshot.DatabaseSnapshot.replaceObject(DatabaseSnapshot.java:363)
[system.out] at liquibase.snapshot.DatabaseSnapshot.replaceObject(DatabaseSnapshot.java:385)
[system.out] at liquibase.snapshot.DatabaseSnapshot.includeNestedObjects(DatabaseSnapshot.java:293)
[system.out] at liquibase.snapshot.DatabaseSnapshot.include(DatabaseSnapshot.java:267)
[system.out] at liquibase.snapshot.DatabaseSnapshot.init(DatabaseSnapshot.java:80)
[system.out] at liquibase.snapshot.DatabaseSnapshot.<init>(DatabaseSnapshot.java:53)
[system.out] at liquibase.snapshot.JdbcDatabaseSnapshot.<init>(JdbcDatabaseSnapshot.java:28)
[system.out] at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:150)
[system.out] at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:139)
[system.out] at liquibase.command.DiffCommand.createReferenceSnapshot(DiffCommand.java:219)
[system.out] at liquibase.command.DiffCommand.createDiffResult(DiffCommand.java:141)
[system.out] at liquibase.command.DiffToChangeLogCommand.run(DiffToChangeLogCommand.java:51)
[system.out] at liquibase.command.AbstractCommand.execute(AbstractCommand.java:8)
[system.out] ... 4 common frames omitted
[org.gradle.process.internal.DefaultExecHandle] Changing state to: FAILED