Class QuarkusArcBeanContainer

java.lang.Object
org.hibernate.resource.beans.container.spi.AbstractCdiBeanContainer
io.quarkus.hibernate.orm.runtime.cdi.QuarkusArcBeanContainer
All Implemented Interfaces:
org.hibernate.resource.beans.container.internal.CdiBasedBeanContainer, org.hibernate.resource.beans.container.spi.BeanContainer, org.hibernate.service.spi.Stoppable

@Singleton public class QuarkusArcBeanContainer extends org.hibernate.resource.beans.container.spi.AbstractCdiBeanContainer
A BeanContainer that works with other build-time elements in Quarkus to achieve a behavior that is as unsurprising as possible, while complying with the Jakarta Persistence spec where possible. The effective behavior is as follows:
  1. When a class is annotated with a scope, such as @ApplicationScoped or @Dependent, we will comply with that (with some gotchas, see last item). This is not in line with the behavior from the Jakarta Persitence spec, which would ignore explicit scopes.
  2. When a class is NOT annotated with any scope, it will behave as a @Dependent CDI bean, at least for attribute converters and entity listeners (with some gotchas, see last item). This is in line with what the Jakarta Persistence spec requires.
  3. Regardless of the above, when a class is annotated with @Vetoed, it will never be instantiated through CDI, but rather through Hibernate ORM's reflection instantiation. This may or may not be in line with the behavior described in the Jakarta Persistence spec -- I did not check -- but seems sensible and intuitive enough.
  4. Hibernate ORM's internal behavior means components may be cached at the persistence unit level, so even for @Dependent components, there would be at most one instance per persistence unit. TODO: this is what we've always done and what we assume in tests, but is this what we want?

    Note this behavior is only possible because we give attribute converters and entity listeners the dependent scope by default: see io.quarkus.hibernate.orm.deployment.HibernateOrmCdiProcessor#registerBeans.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.hibernate.resource.beans.container.spi.BeanContainer

    org.hibernate.resource.beans.container.spi.BeanContainer.LifecycleOptions
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) jakarta.enterprise.inject.spi.BeanManager
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected <B> org.hibernate.resource.beans.container.spi.ContainedBeanImplementor<B>
    createBean(Class<B> beanType, org.hibernate.resource.beans.container.spi.BeanLifecycleStrategy lifecycleStrategy, org.hibernate.resource.beans.spi.BeanInstanceProducer fallbackProducer)
     
    protected <B> org.hibernate.resource.beans.container.spi.ContainedBeanImplementor<B>
    createBean(String name, Class<B> beanType, org.hibernate.resource.beans.container.spi.BeanLifecycleStrategy lifecycleStrategy, org.hibernate.resource.beans.spi.BeanInstanceProducer fallbackProducer)
     
    void
    This will happen after Hibernate ORM is stopped; see io.quarkus.hibernate.orm.runtime.JPAConfig#destroy(java.lang.Object).
    <B> org.hibernate.resource.beans.container.spi.ContainedBean<B>
    getBean(Class<B> beanType, org.hibernate.resource.beans.container.spi.BeanContainer.LifecycleOptions lifecycleOptions, org.hibernate.resource.beans.spi.BeanInstanceProducer fallbackProducer)
     
    <B> org.hibernate.resource.beans.container.spi.ContainedBean<B>
    getBean(String beanName, Class<B> beanType, org.hibernate.resource.beans.container.spi.BeanContainer.LifecycleOptions lifecycleOptions, org.hibernate.resource.beans.spi.BeanInstanceProducer fallbackProducer)
     
    jakarta.enterprise.inject.spi.BeanManager
     

    Methods inherited from class org.hibernate.resource.beans.container.spi.AbstractCdiBeanContainer

    forEachBean, stop

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • beanManager

      @Inject jakarta.enterprise.inject.spi.BeanManager beanManager
  • Constructor Details

    • QuarkusArcBeanContainer

      public QuarkusArcBeanContainer()
  • Method Details

    • getUsableBeanManager

      public jakarta.enterprise.inject.spi.BeanManager getUsableBeanManager()
    • getBean

      public <B> org.hibernate.resource.beans.container.spi.ContainedBean<B> getBean(Class<B> beanType, org.hibernate.resource.beans.container.spi.BeanContainer.LifecycleOptions lifecycleOptions, org.hibernate.resource.beans.spi.BeanInstanceProducer fallbackProducer)
      Specified by:
      getBean in interface org.hibernate.resource.beans.container.spi.BeanContainer
      Overrides:
      getBean in class org.hibernate.resource.beans.container.spi.AbstractCdiBeanContainer
    • getBean

      public <B> org.hibernate.resource.beans.container.spi.ContainedBean<B> getBean(String beanName, Class<B> beanType, org.hibernate.resource.beans.container.spi.BeanContainer.LifecycleOptions lifecycleOptions, org.hibernate.resource.beans.spi.BeanInstanceProducer fallbackProducer)
      Specified by:
      getBean in interface org.hibernate.resource.beans.container.spi.BeanContainer
      Overrides:
      getBean in class org.hibernate.resource.beans.container.spi.AbstractCdiBeanContainer
    • createBean

      protected <B> org.hibernate.resource.beans.container.spi.ContainedBeanImplementor<B> createBean(Class<B> beanType, org.hibernate.resource.beans.container.spi.BeanLifecycleStrategy lifecycleStrategy, org.hibernate.resource.beans.spi.BeanInstanceProducer fallbackProducer)
      Specified by:
      createBean in class org.hibernate.resource.beans.container.spi.AbstractCdiBeanContainer
    • createBean

      protected <B> org.hibernate.resource.beans.container.spi.ContainedBeanImplementor<B> createBean(String name, Class<B> beanType, org.hibernate.resource.beans.container.spi.BeanLifecycleStrategy lifecycleStrategy, org.hibernate.resource.beans.spi.BeanInstanceProducer fallbackProducer)
      Specified by:
      createBean in class org.hibernate.resource.beans.container.spi.AbstractCdiBeanContainer
    • destroy

      @PreDestroy public void destroy()
      This will happen after Hibernate ORM is stopped; see io.quarkus.hibernate.orm.runtime.JPAConfig#destroy(java.lang.Object).