为了账号安全,请及时绑定邮箱和手机立即绑定

 java.lang.NullPointerException了 求打大神来帮忙一下谢谢了

 java.lang.NullPointerException了 求打大神来帮忙一下谢谢了

唯在等你 2017-03-25 10:24:45
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&amp;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); } }
查看完整描述

3 回答

?
Royal丶T

TA贡献8条经验 获得超7个赞

//img1.sycdn.imooc.com//596482b70001652110130876.jpg

//img1.sycdn.imooc.com//596482b80001505610090862.jpg

大神快帮我看下为什么报错啊,我在屋头笔记本都能正常运行,换了公司台式电脑上面就报空指针错误,见鬼了!

SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);


查看完整回答
反对 回复 2017-07-11
?
yanrun

TA贡献317条经验 获得超240个赞

你的hibernate配置文件在哪里

查看完整回答
反对 回复 2017-03-28
?
大咪

TA贡献785条经验 获得超332个赞

打上断点,自己单步调试分析下,看看具体那行是空值
查看完整回答
反对 回复 2017-03-27
  • 3 回答
  • 0 关注
  • 1989 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信