For those using Spring's Java configuration classes, you might write the following:
@Autowired
@Bean(name = "sessionFactory")
public SessionFactory getSessionFactory(DataSource dataSource) {
LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource);
sessionBuilder.addProperties(getHibernateProperties());
sessionBuilder.addAnnotatedClasses(Foo.class);
sessionBuilder.addAnnotatedClasses(Bar.class);
sessionBuilder.addAnnotatedClasses(Bat.class);
return sessionBuilder.buildSessionFactory();
}