Hibernate 5.0.11-AttributeConverter类多次注册

我将Spring

Boot升级到1.4.2,将Hibernate升级到5.0.11.Final,并开始看到此错误。HibernateJpaAutoConfiguration即使只声明一次,也不确定为什么要多次注册客户转换器。

当我尝试运行时,将引发以下异常bootRun

任何帮助都是非常可观的。

[32m2016-11-22 12:25:26.469 -- INFO  --                  o.a.c.c.StandardService [main] -- Stopping service Tomcat

[[32m2016-11-22 12:25:26.485 -- INFO -- utoConfigurationReportLoggingInitializer [main] --

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.

[[1;31m2016-11-22 12:25:26.489 -- ERROR -- o.s.b.SpringApplication [main] -- Application startup failed

[org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AssertionFailure: AttributeConverter class [class com.testOrg.converter.InvertedBooleanTFConverter] registered multiple times

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]

at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]

at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]

at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]

at com.testOrg.Application.main(Application.java:17) [main/:?]

Caused by: org.hibernate.AssertionFailure: AttributeConverter class [class com.testOrg.location.uk.service.converter.InvertedBooleanTFConverter] registered multiple times

at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.addAttributeConverter(InFlightMetadataCollectorImpl.java:353) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]

at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.addAttributeConverter(InFlightMetadataCollectorImpl.java:386) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]

at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl$AttributeConverterManager.addAttributeConverter(AnnotationMetadataSourceProcessorImpl.java:321) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]

at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.categorizeAnnotatedClass(AnnotationMetadataSourceProcessorImpl.java:117) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]

at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.<init>(AnnotationMetadataSourceProcessorImpl.java:104) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]

at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.<init>(MetadataBuildingProcess.java:147) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]

at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:141) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]

at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:847) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]

at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:874) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]

at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.3.4.RELEASE.jar:4.3.4.RELEASE]

at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) ~[spring-orm-4.3.4.RELEASE.jar:4.3.4.RELEASE]

at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373) ~[spring-orm-4.3.4.RELEASE.jar:4.3.4.RELEASE]

at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362) ~[spring-orm-4.3.4.RELEASE.jar:4.3.4.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]

... 14 more

Disconnected from the target VM, address: '127.0.0.1:54978', transport: 'socket'

:web:bootRun FAILED

回答:

@EnableAutoconfigurationJPA的某种方式正在传递两个路径进行扫描,因为数据库配置位于子文件夹中,这很有意义。

com.testOrg

com.testOrg.configuration

org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager520行基于找到的扫描配置路径数量多次添加转换器,我认为对于其他类,我们没有检查重复性,但对于转换器,我们确实检查了它是否被注册了多次,而不是抛出Exception异常。com.testOrg.configuration.MetadataBuilderImpl.java907行

为了解决这个问题,我将DatabaseConfiguration类从"com.testOrg.configuration"文件夹移到main之外,因此只注册了一个类。

我希望这对某人可能有所帮助。

以上是 Hibernate 5.0.11-AttributeConverter类多次注册 的全部内容, 来源链接: utcz.com/qa/406705.html

回到顶部