in a web application we use Spring 3.2 and Hibernate 4.1.1 and implement a plugin-like architecture. Plugins can be added and removed at runtime. For each module, we defined a separate class loader and created a separate child application context for spring. The full configuration is done using annotations, without XML configuration for beans.
Spring Hibernate Configuration Class
@Configuration
@EnableTransactionManagement
public class HibernateConfigurationFactory {
@Bean
public JndiObjectFactoryBean dataSource() {
JndiObjectFactoryBean ds = new JndiObjectFactoryBean();
ds.setJndiName("java:jboss/datasources/OurOwnDS");
ds.setResourceRef(true);
return ds;
}
@Bean
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setPackagesToScan("com.foo.bar");
sessionFactory.setDataSource((DataSource) dataSource().getObject());
Properties hibernateProperties = new Properties();
hibernateProperties.put("hibernate.hbm2ddl.auto", "update");
sessionFactory.setHibernateProperties(hibernateProperties);
return sessionFactory;
}
@Bean
public HibernateTransactionManager transactionManager() {
HibernateTransactionManager transactionManager = new HibernateTransactionManager();
transactionManager.setSessionFactory(sessionFactory().getObject());
return transactionManager;
}
}
Now the problem: Some plugins contain their own entities (+ DAO), which are added along with the module at runtime.
Is it possible to create some kind of separate context in hibernate (as we do it in spring) or even add / reload additional entity classes?
EntityManager ?
?
.
Update:
( .. ).
DataSource + SessionFactory + TransactionManager / ApplicationContext.
scann factory
LocalSessionFactorybean
... ...
:
ClassNotFoundException, , , .
Hibernate pluginClassloader.
- , Hibernate?