public class AccountManager {
private SessionFactory sessionFactory = null;
public AccountManager() {
StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure(“hibernate.cfg.xml").build();
catch (Exception e) {
// The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory, so destroy it manually.
StandardServiceRegistryBuilder.destroy(registry);
}
}
}
2016-04-23
Configuration config = new Configuration().configure().addClass(Students.class);
在config()后面加一個(gè)addClass(Students.class)
5.1.0版的hibernate直接配置hbm.xml就不能識(shí)別,我也有這個(gè)問(wèn)題
2016-10-04
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build();?
//其中?new StandardServiceRegistryBuilder().configure() 這里是默認(rèn)裝載(配置)"hibernate.cfg.xml"這個(gè)文件,當(dāng)然你也可以修改這個(gè)文件名稱(chēng),比如你保存的.cfg.xml文件名為"myHibernate.cfg.xml",那么就在configure()這歌方法里傳入"myHibernate.cfg.xml"這個(gè)參數(shù)就可以了(如下)。
//final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure("myHibernate.cfg.xml").build();?
2016-09-04
真是一個(gè)字母一個(gè)字母的對(duì)啊 就是沒(méi)錯(cuò) ?就是跑不起來(lái) 就是找不到實(shí)體 好痛苦
2016-09-04
我查了半個(gè)小時(shí) 心態(tài)炸了 還好來(lái)問(wèn)答模板看了看 不然我就砸電腦了
2016-04-23
?我查閱了hibernate document,在里面扒到了一種可行的辦法(以下代碼略加修改了一下document里,原始代碼看圖片):
public static SessionFactory getSessionFactory() throws Exception {
// A SessionFactory is set up once for an application!
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.configure() // configures settings from hibernate.cfg.xml
.build();
try {
sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
}
catch (Exception e) {
// The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
// so destroy it manually.
StandardServiceRegistryBuilder.destroy( registry );
}
return sessionFactory;
}