quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.53k stars 2.61k forks source link

Improve error message when multiple hibernate interceptors are found #41992

Closed Postremus closed 1 month ago

Postremus commented 1 month ago

Description

Can this message please be expanded to include the fqdn of the interceptors

__  ____  __  _____   ___  __ ____  ______                                                                                                                                                                                                                                           
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/
2024-07-19 08:41:20,146 WARN  [org.hib.dia.Dialect] (Quarkus Main Thread) HHH000511: The 11.5.0 version for [org.hibernate.dialect.PostgreSQLDialect] is no longer supported, hence certain features may not work properly. The minimum supported version is 12.0.0. Check the community dialects project for available legacy versions.

2024-07-19 08:41:21,902 ERROR [io.qua.run.Application] (Quarkus Main Thread) Failed to start application (with profile [dev]): java.lang.RuntimeException: Failed to start quarkus
        at io.quarkus.runner.ApplicationImpl.doStart(Unknown Source)
        at io.quarkus.runtime.Application.start(Application.java:101)
        at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:111)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:71)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:44)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:124)
        at io.quarkus.runner.GeneratedMain.main(Unknown Source)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at io.quarkus.runner.bootstrap.StartupActionImpl$1.run(StartupActionImpl.java:113)
        at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: jakarta.persistence.PersistenceException: [PersistenceUnit: <default>] Unable to build Hibernate SessionFactory
        at io.quarkus.hibernate.orm.runtime.boot.FastBootEntityManagerFactoryBuilder.persistenceException(FastBootEntityManagerFactoryBuilder.java:129)
        at io.quarkus.hibernate.orm.runtime.boot.FastBootEntityManagerFactoryBuilder.build(FastBootEntityManagerFactoryBuilder.java:89)
        at io.quarkus.hibernate.orm.runtime.FastBootHibernatePersistenceProvider.createEntityManagerFactory(FastBootHibernatePersistenceProvider.java:72)
        at jakarta.persistence.Persistence.createEntityManagerFactory(Persistence.java:80)
        at jakarta.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
        at io.quarkus.hibernate.orm.runtime.JPAConfig$LazyPersistenceUnit.get(JPAConfig.java:154)
        at io.quarkus.hibernate.orm.runtime.JPAConfig$1.run(JPAConfig.java:61)
        ... 1 more
Caused by: java.lang.IllegalStateException: Multiple instances of Interceptor were found for persistence unit <default>. At most one instance can be assigned to each persistence unit.
        at io.quarkus.hibernate.orm.runtime.PersistenceUnitUtil.singleExtensionInstanceForPersistenceUnit(PersistenceUnitUtil.java:33)
        at io.quarkus.hibernate.orm.runtime.boot.FastBootEntityManagerFactoryBuilder.populate(FastBootEntityManagerFactoryBuilder.java:206)
        at io.quarkus.hibernate.orm.runtime.boot.FastBootEntityManagerFactoryBuilder.build(FastBootEntityManagerFactoryBuilder.java:85)
        ... 6 more

Implementation ideas

No response

quarkus-bot[bot] commented 1 month ago

/cc @gsmet (hibernate-orm), @yrodiere (hibernate-orm)

geoand commented 1 month ago

Agreed, at the very least the method should mention which instances are "competing".

Also from what I can tell, the error could be thrown at build time instead of runtime as the presence of multiple beans is known at build time.

yrodiere commented 1 month ago

Agreed, at the very least the method should mention which instances are "competing".

True. The method to improve is PersistenceUnitUtil.singleExtensionInstanceForPersistenceUnit, you can list beans using instance.handles() and InstanceHandle#getBean(). Similar problems exist in io.quarkus.hibernate.search.orm.elasticsearch.runtime.bean.HibernateSearchBeanUtil#singleExtensionBeanReferenceFor(java.lang.Class<T>, java.lang.String, java.lang.String, java.lang.String) and io.quarkus.hibernate.search.standalone.elasticsearch.runtime.bean.HibernateSearchBeanUtil#singleExtensionBeanReferenceFor(java.lang.Class<T>, java.lang.String, java.lang.String).

PRs welcome!

Also from what I can tell, the error could be thrown at build time instead of runtime as the presence of multiple beans is known at build time.

Also true, but would require more work, and would possibly be much more clunky due to the nice CDI APIs not being available. Wouldn't recommend this change to whoever will fix this, unless they're very familiar with Quarkus internals (Arc in particular).

geoand commented 1 month ago

Wouldn't recommend this change to whoever will fix this

Agreed, just something to keep in mind for the future

Chu3laMan commented 1 month ago

I am interested to work in this issue as long as would some guidance Thanks in advance

yrodiere commented 1 month ago

All the guidance you should need is in the messages above; if that's not enough, ask away, but I won't be providing a step-by-step guide as it would take me as much time as doing it myself.