0

I've seen several similar questions, but none of the suggested solutions helped me.

I am migrating my application from Spring 3.0.5.RELEASE to 4.3.5.Final, and Hibernate 3.6.0.Beta2 to 4.3.5.Final. Application has been working perfectly fine in older versions of Spring and Hibernate.

Primary reason for this upgrade is to support multi-tenancy in our application using Hibernate 4.

Here are some details :

Service Layer

@Service("userServiceBean")
public class UserServiceImpl implements UserService {
private static final Logger logger = MyVacationLogger.getLogger(UserServiceImpl.class);

   @Autowired(required=true)
   private UserDAO userDAO;

   @Transactional(readOnly=true, propagation = Propagation.REQUIRED)
   public UserBean validateUser(UserBean userbean) throws MyVacationRuntimeException
   { .... }
}

DAO Layer

@Repository("UserDAOBean")
public class UserDAOImpl implements UserDAO {

   @Autowired(required=true)
   @Qualifier("commondbSessionFactory")
   private SessionFactory sessFactory;

   @Override
   public UserDTO findUserbyEmail(String email) throws DataAccessException
   {   
      Session sess = sessFactory.getCurrentSession(); << Error Line 
      ....  
   }
}

Error

Caused by: org.hibernate.HibernateException: No Session found for current thread
at     org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:106)
at   org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014)
at com.ellisdon.portal.mv.dao.impl.UserDAOImpl.findUserbyEmail(UserDAOImpl.java:31)
at    com.ellisdon.portal.mv.service.impl.UserServiceImpl.validateUser(UserServiceImpl.java:38)

Any help will be greatly appreciated.

Thanks, Bilal

Andrei Stefan
  • 51,654
  • 6
  • 98
  • 89
BAhmed786
  • 51
  • 5
  • Can you post the complete stack trace and the xml or java configuration for the session factory and transaction manager setup? – Andrei Stefan Jun 30 '14 at 09:40

1 Answers1

0

After opening a session outside a transaction, you need to bind the resource like this

session = sessionFactory.openSession();
TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));