这就是我最终要做的事情。我从这里或邮件列表中都没有得到答案,因此我会认为这种骇人听闻的方法,可能不是正确的方法,但对我有用。
在我的模块中(扩展了abstractmodule):
private final HibernateBundle<MyConfiguration> hibernateBundle = new HibernateBundle<MyConfiguration>(MyModel.class) { @Override public DataSourceFactory getDataSourceFactory(MyConfiguration configuration) { return configuration.getDataSourceFactory(); } };@Providespublic SessionFactory provideSessionFactory(MyConfiguration configuration,Environment environment) { SessionFactory sf = hibernateBundle.getSessionFactory(); if (sf == null) { try { hibernateBundle.run(configuration, environment); } catch (Exception e) { logger.error("Unable to run hibernatebundle"); } } return hibernateBundle.getSessionFactory();}
修订:
public SessionFactory provideSessionFactory(MyConfiguration configuration,Environment environment) { SessionFactory sf = hibernateBundle.getSessionFactory(); if (sf == null) { try { hibernateBundle.run(configuration, environment); return hibernateBundle.getSessionFactory(); } catch (Exception e) { logger.error("Unable to run hibernatebundle"); } } else { return sf; }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)