0

I am using two dataSource x and y in my project. and using 2 transactionManager tmx and tmy respectively for that. Enable synchronization for tmy with SYNCHRONIZATION_ALWAYS and not enable for tmx with SYNCHRONIZATION_NEVER.

while starting up the server, I am getting below error:

Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress at org.hibernate.internal.AbstractSharedSessionContract.checkTransactionNeededForUpdateOperation(AbstractSharedSessionContract.java:398) at org.hibernate.internal.SessionImpl.checkTransactionNeededForUpdateOperation(SessionImpl.java:3558) at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1444) at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1440) at org.springframework.orm.hibernate5.SessionFactoryUtils.flush(SessionFactoryUtils.java:147) at org.springframework.orm.hibernate5.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:95) at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:96) at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:922) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:730) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:714)

<bean id="baseTm" class="org.springframework.orm.hibernate5.HibernateTransactionManager" abstract="true">
            <property name="defaultTimeout" value="${db.transactiontimeout}" />
            <property name="failEarlyOnGlobalRollbackOnly" value="true"/>
    </bean>
    
    <bean id="Tmx" parent="baseTm">
        <property name="transactionSynchronizationName" value="SYNCHRONIZATION_NEVER"/>
        <property name="sessionFactory" ref="hibernateTx"/>
    </bean>

    <bean id="Tmy" parent="baseTm">
        <property name="transactionSynchronizationName" value="SYNCHRONIZATION_ALWAYS"/>
        <property name="sessionFactory" ref="hibernateTy"/>
    </bean>

<bean id="abstractHibernate" depends-on="cacheProvider" abstract="true" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
         <property name="hibernateProperties">
            <props>
               <prop key="hibernate.dialect">myProjectCustomizedDialect</prop>
               <prop key="hibernate.cache.provider_class">myProjectCustomizedEhCacheProvider</prop>
               <prop key="hibernate.cache.use_second_level_cache">true</prop>
               <prop key="hibernate.cache.use_query_cache">true</prop>
               <prop key="hibernate.show_sql">false</prop>
               <prop key="hibernate.format_sql">true</prop>
               <prop key="hibernate.generate_statistics">true</prop>
               <prop key="hibernate.connection.isolation">2</prop>
               <prop key="hibernate.cache.use_structured_entries">false</prop>
               <prop key="hibernate.default_batch_fetch_size">16</prop>
               <prop key="hibernate.max_fetch_depth">0</prop>
               <prop key="hibernate.jdbc.batch_size">20</prop>
               <prop key="hibernate.transaction.coordinator_class">jdbc</prop>
               <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
               <prop key="hibernate.cache.ehcache.missing_cache_strategy">create</prop>
            </props>
         </property>
         </bean>

I debug the issue: in SpringSessionSynchronization class -> beforeCommit method ->

Session session = this.getCurrentSession();

after getting above session when we inspect "this.isTransactionInProgress()", it returns false because of that

if (this.disallowOutOfTransactionUpdateOperations && !this.isTransactionInProgress()) { throw new TransactionRequiredException(exceptionMessage); }

above if condition throws "no transaction is in progress" why this "this.isTransactionInProgress()" status is set-up wrong, it should true instead of false in SpringSessionSynchronization ?

what configuration I am missing here because before upgradation I was working fine.

0 Answers0