I\'m trying to access the current hibernate session in a test case, and getting the following error:
org.hibernate.HibernateException: No Hibernate
Please refer to the Spring documentation. There is a whole chapter on testing, and a section on transaction management:
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/testing.html#testing-tx
I've had success extending AbstractTransactionalJUnit4SpringContextTests, but there's a workaround:
TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
// DAO has access to the session through sessionFactory.getCurrentSession()
myDao.findSomething(id);
}
});