測試Hibernate連線資料庫是否成功
阿新 • • 發佈:2019-01-03
@Test
public void testHibernatConfig(){
Configuration config = new Configuration();
config.configure("hibernate.cfg.xml");
SessionFactory sf = config.buildSessionFactory();
Session s = sf.openSession();
Transaction tx = s.beginTransaction();
SysUserGroup sysUserGroup = new SysUserGroup();
sysUserGroup.setName("銷售部門");
sysUserGroup.setPrincipal("xxx");
sysUserGroup.setRemark("vb");
sysUserGroup.setIncumbent("aa");
s.save(sysUserGroup);
tx.commit();
s.close();
public void testHibernatConfig(){
Configuration config = new Configuration();
config.configure("hibernate.cfg.xml");
SessionFactory sf = config.buildSessionFactory();
Session s = sf.openSession();
Transaction tx = s.beginTransaction();
SysUserGroup sysUserGroup = new SysUserGroup();
sysUserGroup.setName("銷售部門");
sysUserGroup.setPrincipal("xxx");
sysUserGroup.setRemark("vb");
sysUserGroup.setIncumbent("aa");
s.save(sysUserGroup);
tx.commit();
s.close();
}