# Hibernate transaction management

**URL:** <https://discourse.hibernate.org/t/hibernate-transaction-management/2373>\
**Category:** Hibernate ORM\
**Created:** [February 26, 2019, 4:43pm UTC](https://discourse.hibernate.org/t/hibernate-transaction-management/2373 "2019-02-26T16:43:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandeep\_kamath](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/sandeep_kamath/32/817_2.png) [@sandeep\_kamath](https://discourse.hibernate.org/u/sandeep_kamath)\
**Post date:** [February 26, 2019, 4:43pm UTC](https://discourse.hibernate.org/t/hibernate-transaction-management/2373/1 "2019-02-26T16:43:47Z")

</div>

As part of hibernate migration from 3 to 5, i am facing some issues related to the transactional entity.  
I am using Spring and hibernate and in this case, i am using spring managed Transactional annotation.  
Consider the case where One method with transactional calls 2 different methods with/without the transaction.  
In hibernate 3 it used to work properly. But after upgrade to hibernate 5 setEMSStatus is failing as subscribedEms is null.

```auto
//Class1
@Transactional(rollbackFor = Exception.class)
public void validateAndSave(List<EmsDto> gridList) {
	//Removing unnecessary code
	emsEntityManager.createAndSaveSubscribedEms(EmsDto.getMessageName(), EmsDto.getDescription(), SubscribeEmsStatus.UNKNOWN.toString());
	//Removing unnecessary code
    emsEntityManager.setEMSStatus(entry.getKey(), SubscribeEmsStatus.VALID.toString());
}
	
//Class2
@Transactional
public void createAndSaveSubscribedEms(final String messageName, final String description, final String status) {
    session.save(SubscribedEms.create(messageName, description, status));
}
// Note: No transactional and it was working earlier in hibernate 3	
public void setEMSStatus(String emsName, String newStatus) {
    SubscribedEms subscribedEms = (SubscribedEms) session.createCriteria(SubscribedEms.class).
        add(Restrictions.eq(SubscribedEms_.messageName, emsName)).
        uniqueResult();
    subscribedEms.setStatus(newStatus);
}

```

I came across a similar issue

> **[Migrating from Hibernate 3 to 4 with Spring integration](https://www.javacodegeeks.com/2013/03/migrating-from-hibernate-3-to-4-with-spring-integration.html)**
>
> This week it was time to upgrade our code base to the latest Hibernate 4.x. We postponed our migrati...

  
I want to know if there is any change in the way Transaction is managed.

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [February 26, 2019, 5:07pm UTC](https://discourse.hibernate.org/t/hibernate-transaction-management/2373/2 "2019-02-26T17:07:16Z")

</div>

This is not a Hibernate issue, it’s a Spring configuration one. So, you need to ask the question on the Spring forum.

---

<div class="post-metadata">

**Author:** ![sandeep\_kamath](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/sandeep_kamath/32/817_2.png) [@sandeep\_kamath](https://discourse.hibernate.org/u/sandeep_kamath)\
**Post date:** [March 4, 2019, 3:31am UTC](https://discourse.hibernate.org/t/hibernate-transaction-management/2373/3 "2019-03-04T03:31:39Z")

</div>

I agree @Transactional is from spring. I have upgraded just hibernate and no changes were made to spring.

Below is the configuration xml (Spring 4.3.4, Hibernate 5.1.15 & Jboss 10).  
Should i set any hibernate property or any spring-hibernate configuration ?

I have started discussion but still no help from the spring community

> <https://stackoverflow.com/questions/54891385/transactional-in-spring>

```auto
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
                        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
                        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd"
        >

    <context:annotation-config />

    <context:component-scan base-package="com.company.product.da">
        <context:exclude-filter type="regex" expression="com\.company\.product\..*Test\$.*"/>
        <context:exclude-filter type="regex" expression="com\.company\.product\..*TestSupport\$.*"/>
    </context:component-scan>

    <context:component-scan base-package="com.company.product.entity.platform.event">
        <context:exclude-filter type="regex" expression="com\.companthis partct\..*Test\$.*"/>
    </context:component-scan>

    <jee:jndi-lookup id="jtaTransactionManager" jndi-name="java:/TransactionManager"/>
    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" depends-on="jtaTransactionManager"/>

    <import resource="classpath:spring/database-common.xml"/>

    <bean id="eventListenerIntegrator" class="com.company.product.persist.hibernate.EventListenerIntegrator"/>

    <bean id="hibernateSessionFactory" class="com.company.product.persist.hibernate.CustomHibernateSessionFactoryBean"
        depends-on="migrationVersionVerifier">
        <constructor-arg ref = "customInfinispanRegionFactory"/>
        <constructor-arg ref = "eventListenerIntegrator"/>
        <property name="hibernateProperties" ref="optionValueStoreProperties" />
        <property name="packagesToScan" value="com.company.product.entity" />
        <property name="dataSource" ref="dataSource" />
    </bean>
</beans>

```
