六祎-在测试中添加测试数据(不在mysql可视化工具添加数据)

//添加测试数据
	@Test
	public void testSaveStudents() {
		// 创建一个配置对象
		Configuration config = new Configuration().configure();
		// 创建服务注册对象
		// ServiceRegistry serviceRegistry = new
		// StandardServiceRegistryBuilder().applySetting(null,
		// config.getProperties()).getBootstrapServiceRegistry();
		// ServiceRegistry serviceRegistry = new
		// StandardServiceRegistryBuilder().configure().build();
		ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties())
				.buildServiceRegistry();
		// 创建sessionFactory
		SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
		// 创建sessio对象
		Session session = sessionFactory.getCurrentSession();
		//创建事务
		Transaction tx = session.beginTransaction();
		
		Students s1 = new Students("$0000001","张三丰","男",new Date(),"武当山");
		Students s2 = new Students("$0000002","郭靖","男",new Date(),"桃花岛");
		Students s3 = new Students("$0000003","黄蓉","男",new Date(),"桃花岛");
		
		session.save(s1);
		session.save(s2);
		session.save(s3);
		
		tx.commit();
		sessionFactory.close();
		
	}

 

全部评论

相关推荐

10-11 17:45
门头沟学院 Java
走吗:别怕 我以前也是这么认为 虽然一面就挂 但是颇有收获!
点赞 评论 收藏
分享
牛客263158796号:我领羊一面后十天不挂也不推进 今天问hr说等前序的第一批意向发完看情况再看是否推进
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务