本文介绍了模式验证:在表[*]的列[*]中遇到错误的列类型;找到[*],但期望[*]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

启动控制台打印异常时,Spring Boot JPA映射MySQL文本类型列.

Spring Boot JPA mapping MySQL text type column, when startup console print exception.

pom.xml:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.1.RELEASE</version>
    <relativePath />
</parent>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Brixton.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

实体:

 @Column(name = "description", nullable = false, length = 65535, columnDefinition="TEXT")
    @Type(type="org.hibernate.type.StringClobType")
    private String description;

控制台信息:

Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [description] in table [kw_product]; found [text (Types#LONGVARCHAR)], but expecting [varchar(255) (Types#VARCHAR)]
    at org.hibernate.tool.schema.internal.SchemaValidatorImpl.validateColumnType(SchemaValidatorImpl.java:105) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.internal.SchemaValidatorImpl.validateTable(SchemaValidatorImpl.java:92) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.internal.SchemaValidatorImpl.doValidation(SchemaValidatorImpl.java:50) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:91) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:475) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
    ... 21 common frames omitted

推荐答案

我修改org.hibernate.tool.schema.internal.SchemaValidatorImplvalidateColumnType方法添加代码:

I modify org.hibernate.tool.schema.internal.SchemaValidatorImplmethod validateColumnType add code:

        String columnInfoType = columnInformation.getTypeName().toLowerCase(Locale.ROOT);
    if("text".equals(columnInfoType)) {
        return;
    }

这篇关于模式验证:在表[*]的列[*]中遇到错误的列类型;找到[*],但期望[*]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 06:13