java.lang.ExceptionInInitializerError hibernate 問題出現(xiàn)了個空指針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.創(chuàng)建一個配置對象 Configuration config = new Configuration().configure(); //2.創(chuàng)建服務注冊對象// ServiceRegistry serviceRegistry =new?// ServiceRegistryBuilder().applySettings(config.getProperties()).build(); StandardServiceRegistryBuilder ssrb = new? StandardServiceRegistryBuilder().applySettings(config.getProperties()); StandardServiceRegistry ssr = ssrb.build(); //3.創(chuàng)建sessionFactory 會話工廠 SessionFactory sf = config.buildSessionFactory(ssr); Session session =sf.getCurrentSession(); //創(chuàng)建SchemaExport 生成表結構 SchemaExport export =new SchemaExport(config); export.create(true, true); } }
添加回答
舉報
0/150
提交
取消