0

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>

Entity:

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

console info:

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
dur
  • 15,689
  • 25
  • 79
  • 125
Alex Li
  • 1
  • 1
  • 1
  • 1
  • As described in the error, hibernate expected `[varchar(255) (Types#VARCHAR)]` for `description` column but if found `[text (Types#LONGVARCHAR)]`, you have juste to change your column type in database. – andolsi zied Nov 30 '16 at 11:03
  • I have this same error, the strange thing is that in the database my column is a "varchar(max)", but the error still says "longvarchar" was found. Isn't it wrong? Also if I specify the column definition as "VARCHAR(MAX) NULL" in the "@Column" annotation, the same error occurs except it says it expects "varchar(max)" instead of "varchar(255)". – nonzaprej May 09 '17 at 14:47

2 Answers2

2

According to this info you should just replace the @Type annotation with @javax.persistence.Lob and it should work.

Pedro
  • 850
  • 1
  • 10
  • 19
  • This lead me to the right solution for my issue. I simply used the following as my annotations @Lob @Type(type = "org.hibernate.type.TextType") @Column(name = "description") – cluis92 Feb 01 '22 at 20:14
-5

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

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