No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

前端 未结 9 667
情歌与酒
情歌与酒 2020-12-23 17:03

I am getting this exception when I call a DAO method which uses SessionFactory.getCurrentSession(). The DAO class is annotated with @Transactional

9条回答
  •  醉梦人生
    2020-12-23 17:45

    I got the following error:

    org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
        at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)
    

    I fixed this by changing my hibernate properties file

    hibernate.current_session_context_class=thread
    

    My code and configuration file as follows

    session =  getHibernateTemplate().getSessionFactory().getCurrentSession();
    
    session.beginTransaction();
    
    session.createQuery(Qry).executeUpdate();
    
    session.getTransaction().commit();
    

    on properties file

    hibernate.dialect=org.hibernate.dialect.MySQLDialect
    
    hibernate.show_sql=true
    
    hibernate.query_factory_class=org.hibernate.hql.ast.ASTQueryTranslatorFactory
    
    hibernate.current_session_context_class=thread
    

    on cofiguration file

    
    
    
    ${hibernate.dialect}
    ${hibernate.show_sql}         
    ${hibernate.query_factory_class}       
    true
    ${hibernate.current_session_context_class}
    
    
    
    

    Thanks,
    Ashok

提交回复
热议问题