I am trying to upgrade Spring from 4.0.6 to 4.3.9 version. While doing so I am getting following error "javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread". Entire code was working fine earlier but I am getting this error just because of library upgrade. Hibernate version which is being used in my project is 4.3.7.

Here is my applicationcontext.xml

<beans default-autowire="byName"
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
                        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
                        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="persistenceUnitName" value="premier" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="false" />
            </bean>
        </property>
    </bean>

    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
        <property name="url" value="jdbc:oracle:thin:@***:1521:PSPRODDB" />
        <property name="username" value="**" />
        <property name="password" value="*****" />
    </bean>

    <!-- entity manager configuration -->
    <!--<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />-->


    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager" />

    <!-- externals -->
    <bean id="mapperFactory" class="org.dozer.spring.DozerBeanMapperFactoryBean">
        <property name="mappingFiles" value="classpath*:dozerBeanMapping.xml" />
    </bean>

</beans>

My Entity class

@SuppressWarnings("serial")
@Entity
@Table(name = "ROLES")
@NamedQueries({
      @NamedQuery(name = "RoleModuleMO.findById",        query = "SELECT rolemodule FROM RoleModuleMO rolemodule WHERE rolemodule.id =:id");    
@Proxy(lazy = false)
@EntityListeners(value = SimpleAuditListener.class)

public class RoleModuleMO implements Serializable, SimpleAuditable {
    public RoleModuleMO () {
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "ROLEMODULE_ID_SQ")
    @SequenceGenerator(name = "ROLEMODULE_ID_SQ", sequenceName = "ROLEMODULE_ID_SQ")
    private Long id;

    @Column(name="ISVISIBLE", nullable = false)
    private Boolean isVisible;

    @Column(name="ISENABLED", nullable = false)
    private Boolean isEnabled;

    @Column(name="NAME", nullable = false)
    private String name;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public Boolean getVisible() {
        return isVisible;
    }

    public void setVisible(Boolean visible) {
        isVisible = visible;
    }

    public Boolean getEnabled() {
        return isEnabled;
    }

    public void setEnabled(Boolean enabled) {
        isEnabled = enabled;
    }

}

My Service class

@Transactional
public class RolesServiceImpl implements RolesService {
    @PersistenceContext
    private EntityManager em;
    private RolesDAO rolesDAO;
    private Mapper mapper;

    public RolesServiceImpl(RolesDAO rolesDAO, Mapper mapper) {
        this.rolesDAO = rolesDAO;
        this.mapper = mapper;
    }

    @Transactional
    public RoleModule saveOrUpdateModule(RoleModule vo) {
        RoleModuleMO mo = new RoleModuleMO();

        mapper.map(vo, mo);
        mo = rolesDAO.saveOrUpdateModule(mo);
        vo = mapper.map(mo, RoleModule.class);

        return vo;
    }
}

This was working in spring 4.0.6 and after upgrading to 4.3.9 facing the error. Is there any changes made by spring community which is causing this error or there is something else which I need to change?

Thanks in advance.

0

There are 0 best solutions below