我有配置类
public class HibernateConfiguration {
private HibernateConfiguration() {}
public Configuration configuration(Class clazz) {
Configuration c = new Configuration();
c.setProperty(Environment.DRIVER, "org.postgresql.Driver");
c.setProperty(Environment.URL, "jdbc:postgresql://localhost/brush_and_pixel");
c.setProperty(Environment.USER, "postgres");
c.setProperty(Environment.PASS, "solaris");
c.setProperty(Environment.DIALECT, "org.hibernate.dialect.PostgreSQLDialect");
c.setProperty(Environment.AUTOCOMMIT, "true"); //"true");
c.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread");
c.addClass(clazz);
return c;
}
public static HibernateConfiguration getHibernateConfiguration() {
return new HibernateConfiguration();
}
}
我正在测试中访问它:
public void setUp() {
/**/
Configuration c = HibernateConfiguration.getHibernateConfiguration()
.configuration(SettingsGroup.class).addClass(Setting.class);
SessionFactory sessionFactory = c.buildSessionFactory();
settingsGroupDao = new SettingGroupDao();
settingsGroupDao.setSessionFactory(sessionFactory);
}
由于sessionFactory
方法已被弃用,建议获取buildSessionFactory()
的方式是什么?
答案 0 :(得分:0)
示例2.4。获取org.hibernate.SessionFactory
protected void setUp() throws Exception {
// A SessionFactory is set up once for an application
sessionFactory = new Configuration()
.configure() // configures settings from hibernate.cfg.xml
.buildSessionFactory();
}