-
Notifications
You must be signed in to change notification settings - Fork 3k
Migration Guide 3.29
Note
|
We highly recommend the use of Items marked below with ⚙️ ✅ are automatically handled by |
In previous versions of Quarkus, when the persistence unit was deactivated (quarkus.hibernate-orm.active=false
), the application would be allowed to start successfully, but could fail much later upon first access to a Hibernate bean (EntityManager
, Session
, SessionFactory
, …).
Starting with this version of Quarkus, persistence units that are deactivated will lead to a startup failure if Quarkus can detect they are used:
-
Static CDI injection points involving the persistence unit (
@Inject Session session
,@Inject SessionFactory sessionFactory
, …) will cause application startup to fail with an explicit, actionable message. -
Dynamic retrieval of the persistence unit (e.g. through
CDI.getBeanContainer()
/Arc.instance()
, or by injecting anInstance<Session>
) will not be detected on startup, but will cause an exception to be thrown with an explicit, actionable message.
The Hibernate Reactive and Hibernate Search extensions implement a similar behavior for their Mutiny.SessionFactory
/SearchSession
/SearchMapping
CDI beans.
If your application needs to inject a EntityManager/`Session
/EntityManagerFactory
/SessionFactory
or related bean for a persistence unit that can potentially be deactivated or have no URL, you may encounter a startup failure similar to this:
io.quarkus.arc.InactiveBeanException: Bean is not active: SYNTHETIC bean [class=org.hibernate.Session, id=QdxvhYUzh5cgfepxgL43K9-OFvU]
Reason: Persistence unit '<default>' was deactivated through configuration properties. To activate the persistence unit, set configuration property 'quarkus.hibernate-orm.active' to 'true' and configure datasource '<default>'. Refer to https://quarkus.io/guides/datasource for guidance.
To avoid this exception while keeping the bean inactive:
- Configure all extensions consuming this bean as inactive as well, if they allow it, e.g. 'quarkus.someextension.active=false'
- Make sure that custom code only accesses this bean if it is active
- Inject the bean with 'Instance<org.hibernate.Session>' instead of 'org.hibernate.Session'
This bean is injected into:
- io.quarkus.hibernate.orm.config.ConfigActiveFalseStaticInjectionTest$MyBean#session
[...]
To avoid this failure, follow the instructions in the exception message.
In particular, consider injecting the problematic bean as an InjectableInstance
(for example @Inject InjectableInstance<Session> session
) instead.
You can check whether that bean is active using .getHandle().getBean().isActive().result()
on the InjectableInstance
, and retrieve the bean instance using InjectableInstance#get()
.
See https://quarkus.io/guides/hibernate-orm#persistence-unit-active for an example of such a setup for Session
.
Starting with this version of Quarkus, Hibernate Reactive persistence units that are deactivated will lead to a startup failure if Quarkus can detect they are used.
See the datasources,similar migration guide entry for Hibernate ORM for more information.
Starting with this version of Quarkus, Hibernate Search mappings that are deactivated will lead to a startup failure if Quarkus can detect they are used.
See the datasources,similar migration guide entry for Hibernate ORM for more information.