-
Couldn't load subscription status.
- Fork 41.6k
Description
When using a different JPA implementation than Hibernate, HibernateMetricsAutoConfiguration (link) will fail, as it is based on Hibernate components.
The following happens usually:
Hibernate is initialized before this auto configuration class. Then HibernateMetricsAutoConfiguration will be checked for conditions
@ConditionalOnClass({ EntityManagerFactory.class, MeterRegistry.class })
@ConditionalOnBean({ EntityManagerFactory.class, MeterRegistry.class })
The conditions are matching, so the auto configuration class will be taken into account.
Without Hibernate:
Any other JPA vendor (e. g. Eclipse Link) will be set up. Now, with micrometer also active, we also will have as well class and bean of EntityManagerFactory and MeterRegistry. Now again, HibernateMetricsAutoConfiguration will be taken into account. As now, hibernate is not in the classpath, we will get java.lang.ClassNotFoundException: org.hibernate.SessionFactory.
Suggestion for a fix
This should be easy to fix, by adding a third class to @ConditionalOnClass. That class should be specific to Hibernate, to make sure, that the JPA vendor really is Hibernate. So the fix could be:
@ConditionalOnClass({ EntityManagerFactory.class, MeterRegistry.class, SessionFactory.class })
@ConditionalOnBean({ EntityManagerFactory.class, MeterRegistry.class })
I can take care of this and provide a PR, if this is confirmed. Not sure, if there is a more appropriate way to tell, if the JPA vendor is Hibernate.