我正在升级到 Boot 3,同时从MySql升级到Postgres(我知道我可能应该一次做一个),我的枚举遇到了问题。
CREATE TYPE calc_sales_status_enum AS ENUM (
'NoUse',
'InUse',
'Vulnerable',
'PartiallyVulnerable',
'PartialUse'
);
然后,我将按如下方式设置每个ENUM
@Enumerated(EnumType.STRING)
@GenericField(sortable = Sortable.YES)
var calcSalesStatus: SalesStatus? = null
它编译得非常好,但是当我运行一个hib查询(insert/update/fetch)时,我收到一条错误消息,详细说明它不能被Map
17:05:02.177 [main] WARN o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 42804
17:05:02.177 [main] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - ERROR: column "status" is of type status_enum but expression is of type character varying
Hint: You will need to rewrite or cast the expression.
Position: 177
17:05:02.177 [main] INFO o.h.e.j.b.internal.AbstractBatchImpl - HHH000010: On release of batch it still contained JDBC statements
因此,为了解决这个问题,我使用推荐的hypersistentutils库来设置类型
@Enumerated(EnumType.STRING)
@Type(PostgreSQLEnumType::class)
@GenericField(sortable = Sortable.YES)
var calcSalesStatus: SalesStatus? = null
现在,我的所有测试都按预期工作,并且获得了100%的成功测试,但是当我在本地运行应用程序时,我得到了以下错误
17:23:36.157 [main] ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Cannot read the array length because "<local3>" is null
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1751)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:599)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1130)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:905)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:584)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:432)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291)
at io.novaware.abinbev.ABInBevApplicationKt.main(ABInBevApplication.kt:59)
Caused by: java.lang.NullPointerException: Cannot read the array length because "<local3>" is null
at org.hibernate.type.EnumType.getAnnotation(EnumType.java:238)
at org.hibernate.type.EnumType.getEnumType(EnumType.java:229)
at org.hibernate.type.EnumType.setParameterValues(EnumType.java:137)
at io.hypersistence.utils.hibernate.type.basic.PostgreSQLEnumType.setParameterValues(PostgreSQLEnumType.java:46)
at org.hibernate.mapping.MappingHelper.injectParameters(MappingHelper.java:70)
at org.hibernate.boot.model.TypeDefinition.createResolution(TypeDefinition.java:161)
at org.hibernate.boot.model.TypeDefinition.createLocalResolution(TypeDefinition.java:299)
at org.hibernate.mapping.BasicValue.interpretExplicitlyNamedType(BasicValue.java:681)
at org.hibernate.mapping.BasicValue.buildResolution(BasicValue.java:353)
at org.hibernate.mapping.BasicValue.resolve(BasicValue.java:315)
at org.hibernate.mapping.BasicValue.resolve(BasicValue.java:305)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.lambda$processValueResolvers$4(InFlightMetadataCollectorImpl.java:1767)
at java.base/java.util.ArrayList.removeIf(ArrayList.java:1682)
at java.base/java.util.ArrayList.removeIf(ArrayList.java:1660)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processValueResolvers(InFlightMetadataCollectorImpl.java:1766)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1752)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.buildMetadataInstance(InFlightMetadataCollectorImpl.java:2292)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:349)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1350)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1421)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:66)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:376)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:352)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1797)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1747)
... 16 common frames omitted
你知道是什么问题吗?
额外帮助:我使用的是Kotlin1.8、java 17,这是我的依赖关系树https://pastebin.com/9EUKVpGM
1条答案
按热度按时间mwg9r5ms1#
为了防止任何人遇到这个问题,我们先把这个问题放在这里,这个问题是在libray hypersistence-utils中,并且是一个高于6.1的hib版本。看起来这个问题在一段时间内不会得到修复。因此,必须在列字段中设置特定的枚举名称
https://github.com/vladmihalcea/hypersistence-utils/issues/519