注册 登录
编程论坛 JAVA论坛

junit测试用例,测试失败

JS1020 发布于 2017-06-06 10:48, 1725 次点击
package entity;

import java.util.EnumSet;

import org.hibernate.SessionFactory;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.schema.TargetType;
import org.junit.Test;
public class TestStudents {
@Test
public void testSchemaExport()
    {
      //创建配置对象
    Configuration config = new Configuration().configure();
    //创建服务注册对象
    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();
    //创建sessionFactory
    //SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
    //创建session对象
    //Session session = sessionFactory.getCurrentSession();
    //创建SchemaExport对象
    Metadata metadata = new MetadataSources(serviceRegistry).buildMetadata();
    SchemaExport export = new SchemaExport();
    System.out.println(export.toString());
    export.create(EnumSet.of(TargetType.DATABASE), metadata);
    }
}
只有本站会员才能查看附件,请 登录
1 回复
#2
GrayJerry2017-06-11 11:43
错误是找不到映射关系,是不是映射关系没添加
1