Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpringBeanContainer for Hibernate 5 does not deal with NoSuchBeanDefinitionException [SPR-17430] #21963

Closed
spring-issuemaster opened this issue Oct 25, 2018 · 1 comment
Assignees
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Oct 25, 2018

Phil Webb opened SPR-17430 and commented

Originally raised as a Spring Boot issue with a sample application.

The fallback logic fixed in #21548 works by catching BeanCreationException but unfortunately that doesn't seem to cover all cases. We probably need to additionally catch NoSuchBeanDefinitionException.

The sample application provided throws the following stacktrace:

java.lang.reflect.InvocationTargetException
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:558)
    at java.lang.Thread.run (Thread.java:834)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.search.exception.SearchException: HSEARCH000139: Unable to instantiate FieldBridge for uid of class java.util.UUID
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean (AbstractAutowireCapableBeanFactory.java:1745)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java:576)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java:498)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0 (AbstractBeanFactory.java:320)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java:318)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:199)
    at org.springframework.context.support.AbstractApplicationContext.getBean (AbstractApplicationContext.java:1083)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization (AbstractApplicationContext.java:853)
    at org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java:546)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh (ServletWebServerApplicationContext.java:140)
    at org.springframework.boot.SpringApplication.refresh (SpringApplication.java:771)
    at org.springframework.boot.SpringApplication.refreshContext (SpringApplication.java:395)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:314)
    at config.Application.main (Application.java:46)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:558)
    at java.lang.Thread.run (Thread.java:834)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.search.exception.SearchException: HSEARCH000139: Unable to instantiate FieldBridge for uid of class java.util.UUID
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory (AbstractEntityManagerFactoryBean.java:402)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet (AbstractEntityManagerFactoryBean.java:377)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet (LocalContainerEntityManagerFactoryBean.java:341)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods (AbstractAutowireCapableBeanFactory.java:1804)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean (AbstractAutowireCapableBeanFactory.java:1741)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java:576)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java:498)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0 (AbstractBeanFactory.java:320)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java:318)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:199)
    at org.springframework.context.support.AbstractApplicationContext.getBean (AbstractApplicationContext.java:1083)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization (AbstractApplicationContext.java:853)
    at org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java:546)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh (ServletWebServerApplicationContext.java:140)
    at org.springframework.boot.SpringApplication.refresh (SpringApplication.java:771)
    at org.springframework.boot.SpringApplication.refreshContext (SpringApplication.java:395)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:314)
    at config.Application.main (Application.java:46)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:558)
    at java.lang.Thread.run (Thread.java:834)
Caused by: org.hibernate.search.exception.SearchException: HSEARCH000139: Unable to instantiate FieldBridge for uid of class java.util.UUID
    at org.hibernate.search.bridge.impl.BridgeFactory.createFieldBridgeFromAnnotation (BridgeFactory.java:400)
    at org.hibernate.search.bridge.impl.BridgeFactory.findExplicitFieldBridge (BridgeFactory.java:350)
    at org.hibernate.search.bridge.impl.BridgeFactory.buildFieldBridge (BridgeFactory.java:203)
    at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.bindFieldAnnotation (AnnotationMetadataProvider.java:1335)
    at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.checkForField (AnnotationMetadataProvider.java:1258)
    at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.initializeMemberLevelAnnotations (AnnotationMetadataProvider.java:1065)
    at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.initializeClass (AnnotationMetadataProvider.java:615)
    at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.doGetTypeMetadataFor (AnnotationMetadataProvider.java:192)
    at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.getTypeMetadataFor (AnnotationMetadataProvider.java:181)
    at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.getTypeMetadataFor (AnnotationMetadataProvider.java:165)
    at org.hibernate.search.spi.SearchIntegratorBuilder.initDocumentBuilders (SearchIntegratorBuilder.java:445)
    at org.hibernate.search.spi.SearchIntegratorBuilder.createNewFactoryState (SearchIntegratorBuilder.java:244)
    at org.hibernate.search.spi.SearchIntegratorBuilder.buildNewSearchFactory (SearchIntegratorBuilder.java:200)
    at org.hibernate.search.spi.SearchIntegratorBuilder.buildSearchIntegrator (SearchIntegratorBuilder.java:128)
    at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.boot (HibernateSearchSessionFactoryObserver.java:127)
    at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated (HibernateSearchSessionFactoryObserver.java:94)
    at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated (SessionFactoryObserverChain.java:35)
    at org.hibernate.internal.SessionFactoryImpl.<init> (SessionFactoryImpl.java:372)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build (SessionFactoryBuilderImpl.java:467)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build (EntityManagerFactoryBuilderImpl.java:939)
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory (SpringHibernateJpaPersistenceProvider.java:57)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory (LocalContainerEntityManagerFactoryBean.java:365)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory (AbstractEntityManagerFactoryBean.java:390)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet (AbstractEntityManagerFactoryBean.java:377)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet (LocalContainerEntityManagerFactoryBean.java:341)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods (AbstractAutowireCapableBeanFactory.java:1804)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean (AbstractAutowireCapableBeanFactory.java:1741)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java:576)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java:498)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0 (AbstractBeanFactory.java:320)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java:318)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:199)
    at org.springframework.context.support.AbstractApplicationContext.getBean (AbstractApplicationContext.java:1083)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization (AbstractApplicationContext.java:853)
    at org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java:546)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh (ServletWebServerApplicationContext.java:140)
    at org.springframework.boot.SpringApplication.refresh (SpringApplication.java:771)
    at org.springframework.boot.SpringApplication.refreshContext (SpringApplication.java:395)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:314)
    at config.Application.main (Application.java:46)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:558)
    at java.lang.Thread.run (Thread.java:834)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.locationguru.app.model.UUIDBridge' available
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean (DefaultListableBeanFactory.java:343)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean (DefaultListableBeanFactory.java:335)
    at org.springframework.orm.hibernate5.SpringBeanContainer.createBean (SpringBeanContainer.java:154)
    at org.springframework.orm.hibernate5.SpringBeanContainer.getBean (SpringBeanContainer.java:109)
    at org.hibernate.search.cfg.impl.HibernateOrmBeanContainerBeanResolver.resolve (HibernateOrmBeanContainerBeanResolver.java:63)
    at org.hibernate.search.engine.service.beanresolver.impl.ReflectionFallbackBeanResolver.resolve (ReflectionFallbackBeanResolver.java:40)
    at org.hibernate.search.bridge.impl.BridgeFactory.createFieldBridgeFromAnnotation (BridgeFactory.java:371)
    at org.hibernate.search.bridge.impl.BridgeFactory.findExplicitFieldBridge (BridgeFactory.java:350)
    at org.hibernate.search.bridge.impl.BridgeFactory.buildFieldBridge (BridgeFactory.java:203)
    at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.bindFieldAnnotation (AnnotationMetadataProvider.java:1335)
    at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.checkForField (AnnotationMetadataProvider.java:1258)
    at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.initializeMemberLevelAnnotations (AnnotationMetadataProvider.java:1065)
    at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.initializeClass (AnnotationMetadataProvider.java:615)
    at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.doGetTypeMetadataFor (AnnotationMetadataProvider.java:192)
    at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.getTypeMetadataFor (AnnotationMetadataProvider.java:181)
    at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.getTypeMetadataFor (AnnotationMetadataProvider.java:165)
    at org.hibernate.search.spi.SearchIntegratorBuilder.initDocumentBuilders (SearchIntegratorBuilder.java:445)
    at org.hibernate.search.spi.SearchIntegratorBuilder.createNewFactoryState (SearchIntegratorBuilder.java:244)
    at org.hibernate.search.spi.SearchIntegratorBuilder.buildNewSearchFactory (SearchIntegratorBuilder.java:200)
    at org.hibernate.search.spi.SearchIntegratorBuilder.buildSearchIntegrator (SearchIntegratorBuilder.java:128)
    at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.boot (HibernateSearchSessionFactoryObserver.java:127)
    at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated (HibernateSearchSessionFactoryObserver.java:94)
    at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated (SessionFactoryObserverChain.java:35)
    at org.hibernate.internal.SessionFactoryImpl.<init> (SessionFactoryImpl.java:372)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build (SessionFactoryBuilderImpl.java:467)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build (EntityManagerFactoryBuilderImpl.java:939)
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory (SpringHibernateJpaPersistenceProvider.java:57)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory (LocalContainerEntityManagerFactoryBean.java:365)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory (AbstractEntityManagerFactoryBean.java:390)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet (AbstractEntityManagerFactoryBean.java:377)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet (LocalContainerEntityManagerFactoryBean.java:341)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods (AbstractAutowireCapableBeanFactory.java:1804)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean (AbstractAutowireCapableBeanFactory.java:1741)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java:576)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java:498)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0 (AbstractBeanFactory.java:320)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java:318)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:199)
    at org.springframework.context.support.AbstractApplicationContext.getBean (AbstractApplicationContext.java:1083)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization (AbstractApplicationContext.java:853)
    at org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java:546)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh (ServletWebServerApplicationContext.java:140)
    at org.springframework.boot.SpringApplication.refresh (SpringApplication.java:771)
    at org.springframework.boot.SpringApplication.refreshContext (SpringApplication.java:395)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:314)
    at config.Application.main (Application.java:46)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:558)
    at java.lang.Thread.run (Thread.java:834)

Affects: 5.1.1

Reference URL: spring-projects/spring-boot#14935

Issue Links:

  • #21548 org.springframework.orm.hibernate5.SpringBeanContainer ignores the fallback bean instance producer

Referenced from: commits 3681d58

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 25, 2018

Juergen Hoeller commented

We're catching any BeansException there now, leniently falling back to Hibernate's default producer in all cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.