You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
HibernateJpaAutoConfiguration should be applied beforeDatasourceTransactionManagerAutoconfiguration
Explanation: HibernateJpaAutoConfiguration imports HibernateJpaBaseConfiguration which contains a Bean definition of a JPATransactionManager with ConditionalOnMissingBean(TransactionManager) (in superclass JpaBaseConfiguration):
If the application uses Hibernate, the Hibernate auto-configuration should match, which means that the HibernateJpaAutoConfiguration should be applied beforeDatasourceTransactionManagerAutoConfiguration.
Currently, there is no explicit before/after Condition for these Autoconfigurations, but the 'natural' sort order leads 'by chance' to the right order.
We provided for our application a additional auto-configuration with these conditions:
@AutoConfiguration(
after = {RestTemplateAutoconfiguration.class, TransactionAutoConfiguration.class}
)
which leaded to a different order of many Spring auto-configuration, especially now sorting DatasourceTransactionManagerAutoConfigurationbeforeHibernateJpaAutoConfiguration. As a result, we saw this exception during execution of the application:
14:22:47 [43-exec-7] ERROR d.l.a.a.b.r.GlobalExceptionHandler - Caught unhandled exception
org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress
at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:400)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:234)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:550)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:243)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:152)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:164)
...
Caused by: jakarta.persistence.TransactionRequiredException: no transaction is in progress
at org.hibernate.internal.AbstractSharedSessionContract.checkTransactionNeededForUpdateOperation(AbstractSharedSessionContract.java:483)
at org.hibernate.internal.SessionImpl.checkTransactionNeededForUpdateOperation(SessionImpl.java:2528)
at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1406)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1401)
The text was updated successfully, but these errors were encountered:
tvahrst
changed the title
HibernateJpaAutoConfiguration should have precedence over DataSourceTransactionManagerAutoConfiguration
HibernateJpaAutoConfiguration should be applied before DataSourceTransactionManagerAutoConfiguration
Dec 19, 2023
HibernateJpaAutoConfiguration
should be applied beforeDatasourceTransactionManagerAutoconfiguration
Explanation:
HibernateJpaAutoConfiguration
importsHibernateJpaBaseConfiguration
which contains a Bean definition of aJPATransactionManager
withConditionalOnMissingBean(TransactionManager)
(in superclass JpaBaseConfiguration):The
DatasourceTransactionManagerAutoConfiguration
does also define aTransactionManager
Bean with the same condition:If the application uses Hibernate, the Hibernate auto-configuration should match, which means that the
HibernateJpaAutoConfiguration
should be applied beforeDatasourceTransactionManagerAutoConfiguration
.Currently, there is no explicit before/after Condition for these Autoconfigurations, but the 'natural' sort order leads 'by chance' to the right order.
We provided for our application a additional auto-configuration with these conditions:
which leaded to a different order of many Spring auto-configuration, especially now sorting
DatasourceTransactionManagerAutoConfiguration
beforeHibernateJpaAutoConfiguration
. As a result, we saw this exception during execution of the application:The text was updated successfully, but these errors were encountered: