Friday, August 24, 2012

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

To solve this problem. You have to do two things:

1. mark the DAO as transactional or function which is doing database call like:

   public class EmployeeDaoImpl  extends DaoImpl implements EmployeeDao{
    public long addEmployee(Employee employee) {
        System.out.println("Employee:"+employee );
        long id = employeeDao.addEmployee(employee);
        System.out.println("Id1: " );
        return id;

2. Enable the annotation driven transcation management in applicationContext.xml (where your beans are defined):

<beans xmlns=""
    xmlns:xsi="" xmlns:p=""
<!-- Main transaction manager for accessing internal DB -->
    <bean id="transactionManager"
        <property name="sessionFactory" ref="sessionFactory" />
    <!-- enable the configuration of transactional behavior based on annotations -->
  <tx:annotation-driven transaction-manager="transactionManager"/>

That's it. Hope it works for other too.

No comments:

Post a Comment

How TOPT Works: Generating OTPs Without Internet Connection

Introduction Have you ever wondered how authentication apps like RSA Authenticator generate One-Time Passwords (OTPs) without requiring an i...