public class HibernateModule implements Module {
Log log = LogFactory.getLog(HibernateModule.class);
public void configure(Binder binder) {
AnnotationConfiguration configuration = new AnnotationConfiguration();
if (!configuration.getProperties().contains("hibernate.current_session_context_class")) {
log.info("Defaulting hibernate.current_session_context_class to managed");
configuration.setProperty("hibernate.current_session_context_class", "managed");
}
binder.bind(AnnotationConfiguration.class).toInstance(configuration);
SessionFactory sessionFactory = configuration.configure().buildSessionFactory();
binder.bind(SessionFactory.class).toInstance(sessionFactory);
// Guice/AssistedInject seems to need an explicit binding.
// this may be able to go away in fiture version of guice
binder.bind(HibernateUtil.class).to(HibernateUtilImpl.class);