private SessionFactory createTestSessionFactory() throws Exception { // create a FactoryBean to help create a Hibernate SessionFactory AnnotationSessionFactoryBean factoryBean = new AnnotationSessionFactoryBean(); factoryBean.setDataSource(createTestDataSource()); factoryBean.setAnnotatedClasses(new Class[] {Account.class, Beneficiary.class}); factoryBean.setHibernateProperties(createHibernateProperties()); // initialize according to the Spring InitializingBean contract factoryBean.afterPropertiesSet(); // get the created session factory return (SessionFactory) factoryBean.getObject(); }