/** * @param pckg string with package containing Hibernate entities (classes annotated with Hibernate {@code @Entity} * annotation) e. g. {@code com.codahale.fake.db.directory.entities} */ protected ScanningHibernateBundle(String pckg) { this(pckg, new SessionFactoryFactory()); }
protected HibernateBundle(Class<?> entity, Class<?>... entities) { final List<Class<?>> entityClasses = new ArrayList<>(); entityClasses.add(entity); entityClasses.addAll(Arrays.asList(entities)); this.entities = Collections.unmodifiableList(entityClasses); this.sessionFactoryFactory = new SessionFactoryFactory(); }
/** * @param pckg string with package containing Hibernate entities (classes annotated with Hibernate {@code @Entity} * annotation) e. g. {@code com.codahale.fake.db.directory.entities} */ protected ScanningHibernateBundle(String pckg) { this(pckg, new SessionFactoryFactory()); }
protected HibernateBundle(Class<?> entity, Class<?>... entities) { this(ImmutableList.<Class<?>>builder().add(entity).add(entities).build(), new SessionFactoryFactory()); }
@Singleton public class MyHibernateBundle extends HibernateBundle<NoxboxConfiguration> implements ConfiguredBundle<MyConfiguration> { public MyHibernateBundle() { super(myDbEntities(), new SessionFactoryFactory()); } private static ImmutableList<Class<?>> myDbEntities() { Reflections reflections = new Reflections("com.acme"); ImmutableList<Class<?>> entities = ImmutableList.copyOf(reflections.getTypesAnnotatedWith(Entity.class)); return entities; } @Override public DataSourceFactory getDataSourceFactory(NoxboxConfiguration configuration) { return configuration.getMyDb(); } } @Provides public SessionFactory sessionFactory(MyHibernateBundle hibernate) { return checkNotNull(hibernate.getSessionFactory()); }