MappingException, в то время как liquibase diffChangeLog для типа массива с postgresql и hibernate - PullRequest
2 голосов
/ 04 июля 2019

Я пытаюсь сгенерировать Liquibase diffChangeLog Получение:
Unexpected error running Liquibase: org.hibernate.MappingException: No Dialect mapping for JDBC type: 2003

Кажется, проблема в использовании атрибута массива в сущности.
Для этогомассив, который я создал hibernate UserType, так как hibernate не поддерживает встроенные массивы базы данных.

Может ли кто-нибудь помочь запустить diffChangeLog ?
Не уверен, нужно ли мне настраиватьliquibase или hibernate любым способом ...

(Примечание: команда Liquibase generateChangeLog выполняется успешно)
(Примечание 2: запись и чтение из базы данных в приложении работает нормально)



Используемое программное обеспечение:
  • postgresql 9,6
  • hibernate 5.2.17Final
  • liquibase 3.5.5
  • spring 2.0.4
  • spring-data 2.0.9
  • java 8 / kotlin 1.3.21



Сущность (kotlin)

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
…
}

UserType (java)

import java.sql.Array;

public class CustomArrayType implements UserType {
    public int[] sqlTypes() {
        return new int[]{Types.ARRAY};
    }

    public Class returnedClass() {
        return String[].class;
    }
…
}

Liquibase changeset для объекта с пользовательскиммассив

    <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
    }
}

Running выдает следующую ошибку:

Сообщение об ошибке

[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
...