@Transactional не работает, возможно, плохая конфигурация для sessionfactory.getCurrentSession()

У меня есть приложение spring при использовании Hibernate4, все работает с sessionFactory.openSession() в StageDaoImpl:

@Repository(value = "stageDao")
public class StageDaoImpl implements StageDao {

  @Autowired
  private SessionFactory sessionFactory;

  @Override
  public Integer editStage(Stage stage) {
    Session session = sessionFactory.openSession();
    Integer ban = 1;
    try {
        session.beginTransaction();
        session.update(stage);
        session.getTransaction().commit();
    } catch (HibernateException e) {
        ban = -1;
    } catch (Exception e) {
        ban = -2;
    } finally {
        session.close();
    }
    return ban;
  }

Я пытаюсь изменить editStage на аннотацию @Transactional, но я не знаю, как настроить транзакцию. Это всегда один и тот же результат.

@Repository(value = "stageDao")
public class StageDaoImpl implements StageDao {
  @Autowired
  private SessionFactory sessionFactory;

      @Override
      @Transactional
  public Integer editStage(Stage stage) {
    Session session = sessionFactory.getCurrentSession();
    Integer ban = 1;
    try {  
        session.update(stage);
    } catch (HibernateException e) {
        ban = -1;
    } catch (Exception e) {
        ban = -2;
    }
    return ban;
  }

Ошибка StackTrace:

 org.hibernate.HibernateException: No Session found for current thread

services-config.xml

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

    <!-- holding properties for database connectivity / -->
    <context:property-placeholder location="classpath:/config/jdbc.properties" ignore-unresolvable="true" order="1" />
    <!-- enabling annotation driven configuration / -->
    <context:annotation-config />

    <!-- Sesion factory  -->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
    </bean>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="packagesToScan" value="org.school.graduation.entities"></property>

        <property name="hibernateProperties">
            <props>
                <prop key="dialect">org.hibernate.dialect.InformixDialect</prop>
                <prop key="hibernate.jdbc.use_scrollable_resultset">false</prop>
            </props>
        </property>
    </bean>

    <!-- The only thing in here is the driver for hibernate-->
    <tx:annotation-driven transaction-manager="transactionManager" />

    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

</beans>

servlet-context.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns:mvc="http://www.springframework.org/schema/mvc" 
        xmlns:p="http://www.springframework.org/schema/p" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:beans="http://www.springframework.org/schema/beans" 
        xmlns:context="http://www.springframework.org/schema/context" 
        xmlns:security="http://www.springframework.org/schema/security" 
        xmlns:cache="http://www.springframework.org/schema/cache" 
        xmlns:task="http://www.springframework.org/schema/task" 
        xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
            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/task http://www.springframework.org/schema/task/spring-task-3.0.xsd 
            http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
            http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.2.xsd">

        <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

        <!-- Enables the Spring MVC @Controller programming model -->
        <mvc:annotation-driven />

        <!-- Handles HTTP GET requests for /resources/ by efficiently serving up static resources in the ${webappRoot}/resources directory -->
        <mvc:resources mapping="/resources/**" location="/resources/" />

        <beans:bean id="viewResolver1" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
            <beans:property name="order" value="1" />
            <beans:property name="basename" value="views"/>
        </beans:bean>

        <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
        <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <beans:property name="order" value="1" />
            <beans:property name="prefix" value="/WEB-INF/views/" />
            <beans:property name="suffix" value=".jsp" />
        </beans:bean>

        <!-- Configure the multipart resolver -->
        <beans:bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
            <beans:property name="maxUploadSize" value="50485760" />
        </beans:bean>

        <context:component-scan base-package="org.school.graduation" />

        <task:annotation-driven />

    </beans:beans>

root-context.xml

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

    <!-- Root Context: defines shared resources visible to all other web components -->
    <import resource="classpath:**/*-config.xml"/>

</beans>

StageStepServiceImpl.java

 @Component
    @Service("stageStepService")
    public class StageStepServiceImpl implements StageStepService {
    @Resource(name="stageDao")
        private StageDao stageDao;

@Override
    public Integer generatingStage( Stage stage ) {
        Integer serviceValue = 0;

        try {
            serviceValue = stageDao.editStage(stage);
        } catch (Exception e) {
            serviceValue = -5;
        }

        return serviceValue;
    }

}

это многомодульный проект Maven

graduation-dao
├── src/main/java
│   ├── org.school.graduation.dao.administrator.provider
│   │   └── StageDao.java
│   └── org.school.graduation.dao.administrator.providerImpl 
│       └── StageDaoImpl.java
├── Maven Dependencies
├── JRE System Library
├── src
├── target
└── pom.xml
graduation-services
├── src/main/java
│   ├── org.school.graduation.services.administrator.provider
│   │   └── StageService.java
│   └── org.school.graduation.services.administrator.providerImpl 
│       └── StageServiceImpl.java
├── Maven Dependencies
├── JRE System Library
├── src
├── target
└── pom.xml
graduation-web
├── src/main/java
│   └── org.school.graduation.controller.administrator.provider
│       └── StageController.java  
├── src/main/resources
│   ├── root-context.mxl
│   ├── services-config.mxl
│   └── servlet-context.mxl    
├── Maven Dependencies
├── JRE System Library
├── src
├── target
└── pom.xml

person jesseCon    schedule 18.07.2016    source источник
comment
Как вы вызываете свой editStage()?   -  person aksappy    schedule 18.07.2016
comment
это ваш собственный SessionFactory класс или принадлежит Hibernate ??   -  person Vikrant Kashyap    schedule 18.07.2016
comment
@Vikrant Kashyap SessionFactory от xml (services-config.xml)   -  person jesseCon    schedule 18.07.2016
comment
Вы должны переместить аннотацию @Transactional в свой класс обслуживания StageStepServiceImpl вместо класса StageDaoImpl перед методом editStage   -  person NguaCon    schedule 18.07.2016
comment
@NguaCo тот же результат: сеанс не найден для текущего потока [Ljava.lang.StackTraceElemen   -  person jesseCon    schedule 18.07.2016
comment
Я использую конфигурацию аннотаций. Я опубликую свой ответ.   -  person NguaCon    schedule 18.07.2016
comment
@jesseCont какая версия фреймворка Spring? Вы можете увидеть больше информации в том же вопросе здесь: stackoverflow.com/questions/20716939/   -  person NguaCon    schedule 18.07.2016
comment
Версия @NguaCon: 4.2.1.RELEASE   -  person jesseCon    schedule 18.07.2016
comment
@NguaCon Вам нужна дополнительная информация?   -  person jesseCon    schedule 18.07.2016