我的测试显示绿色,数据库里没有信息

package entity;





import java.util.Date;


import org.hibernate.Session;

import org.hibernate.SessionFactory;

import org.hibernate.Transaction;

import org.hibernate.cfg.Configuration;

import org.hibernate.service.ServiceRegistry;

import org.hibernate.service.ServiceRegistryBuilder;

import org.hibernate.tool.hbm2ddl.SchemaExport;

import org.junit.Test;


public class TestStudents {

     @Test

     public void testSchemaExport(){

    Configuration config = new Configuration().configure();

    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();

         SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);

         Session session = sessionFactory.getCurrentSession();

    SchemaExport export = new SchemaExport(config);

    export.create(true,true);

     }

     @Test

     public void testSaveStudents(){

    Configuration config = new Configuration().configure();

    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();

         SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);

         Session session = sessionFactory.getCurrentSession();

         Transaction tx = session.beginTransaction();

         

         Students s1 = new Students("S0000001","张三丰","男",new Date(),"武当山");

         Students s2 = new Students("S0000002","郭靖","男",new Date(),"桃花岛");

         Students s3 = new Students("S0000003","黄蓉","女",new Date(),"桃花岛");

         

         session.save(s1);

         session.save(s2);

         session.save(s3);

         

         tx.commit();

         sessionFactory.close();

     

     }

}


jiayy
浏览 1382回答 1
1回答

jiayy

明白了,点下三角在testSaveStudent()点junit
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java