我见过几个类似的问题,但没有一个建议的解决方案对我有帮助。
我正在将我的应用程序从 Spring 3.0.5.RELEASE 迁移到 4.3.5.Final,并将 Hibernate 3.6.0.Beta2 迁移到 4.3.5.Final。应用程序在旧版本的 Spring 和 Hibernate 中运行良好。
此次升级的主要原因是使用 Hibernate 4 在我们的应用程序中支持多租户。
以下是一些细节:
服务层
@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 层
@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
....
}
}
错误
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)
任何帮助将不胜感激。
谢谢, 比拉尔