hibernate 如何在mysql和spring-boot中将tinyintMap到Integer?

rm5edbpk  于 2023-08-06  发布在  Mysql
关注(0)|答案(2)|浏览(138)

spring-boot-2.4.5升级到spring-boot-2.5.0
mariadb-java-client-2.7.2升级到mariadb-java-client-2.7.3时出现此问题。但我不知道为什么,也不知道这是一个休眠或更多的mariadb连接器的问题。
现在我的应用程序启动失败,并显示:
found [bit (Types#TINYINT)], but expecting [tinyint unsigned (Types#INTEGER)]
我已经将列声明为@Column("TINYINT")类型的Integer,而在mysql中,它是一个真实的的tinyint,在升级之前没有问题!

@Column(columnDefinition = "TINYINT")
public Integer counter;
    
    
CREATE TABLE foo {
    ... 
    counter tinyint NOT NULL,
    ...
}

字符串
我能怎么办?为什么tinyint突然不支持了?
完整日志:

Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [count] in table [foo]; found [bit (Types#TINYINT)], but expecting [tinyint unsigned (Types#INTEGER)]
    at org.hibernate.tool.schema.internal.AbstractSchemaValidator.validateColumnType(AbstractSchemaValidator.java:159) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at org.hibernate.tool.schema.internal.AbstractSchemaValidator.validateTable(AbstractSchemaValidator.java:143) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at org.hibernate.tool.schema.internal.GroupedSchemaValidatorImpl.validateTables(GroupedSchemaValidatorImpl.java:42) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at org.hibernate.tool.schema.internal.AbstractSchemaValidator.performValidation(AbstractSchemaValidator.java:89) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at org.hibernate.tool.schema.internal.AbstractSchemaValidator.doValidation(AbstractSchemaValidator.java:68) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:192) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:73) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:318) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:468) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1259) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) ~[spring-orm-5.3.8.jar:5.3.8]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.3.8.jar:5.3.8]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409) ~[spring-orm-5.3.8.jar:5.3.8]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) ~[spring-orm-5.3.8.jar:5.3.8]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.3.8.jar:5.3.8]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1845) ~[spring-beans-5.3.8.jar:5.3.8]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1782) ~[spring-beans-5.3.8.jar:5.3.8]
    ... 21 more

flmtquvp

flmtquvp1#

将代码修改为:

@Column(columnDefinition = "TINYINT")
@Type(type = "org.hibernate.type.IntegerType")
public Integer counter;

字符串

t30tvxxf

t30tvxxf2#

现在有类似的问题与 Spring Boot 3.1.1。我对TINYINT UNSIGNEDSMALLINT UNSIGNED的定义停止了工作。我通过将定义更改为TINYINT(3) UNSIGNED & SMALLINT(5) UNSIGNED来解决这个问题,它设置了列的显示宽度,与值范围无关。更多信息请参见in official mysql 8 doc here
请让我知道,如果其他人有同样的问题或知道的原因!不喜欢为每一列都指定这个…

相关问题