java.lang.ExceptionInInitializerError hibernate 问题出现了个空指针Configuration config = new Configuration().configure();老显示错误我就不知道怎么改了 求大神们帮一下谢谢我是一个可爱的小萌新<hibernate-configuration> <session-factory> <property name="connection.username">root</property> <property name="connection.password">123456</property> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="show_sql">true</property> <property name="format_sql">true</property> <property name="hbm2ddl.auto">update</property> <property name="hibernate.current_session_context_class">thread</property> <!--对应的映射 --> <mapping resource="entity/Students.hbm.xml" /> <mapping resource="entity/Users.hbm.xml" /> </session-factory></hibernate-configuration>package entity;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.boot.registry.StandardServiceRegistry;import org.hibernate.boot.registry.StandardServiceRegistryBuilder;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(){ //1.创建一个配置对象 Configuration config = new Configuration().configure(); //2.创建服务注册对象// ServiceRegistry serviceRegistry =new // ServiceRegistryBuilder().applySettings(config.getProperties()).build(); StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySettings(config.getProperties()); StandardServiceRegistry ssr = ssrb.build(); //3.创建sessionFactory 会话工厂 SessionFactory sf = config.buildSessionFactory(ssr); Session session =sf.getCurrentSession(); //创建SchemaExport 生成表结构 SchemaExport export =new SchemaExport(config); export.create(true, true); } }
添加回答
举报
0/150
提交
取消