猿问

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

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);

}

}



唯在等你
浏览 2001回答 3
3回答

Royal丶T

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

yanrun

你的hibernate配置文件在哪里

大咪

打上断点,自己单步调试分析下,看看具体那行是空值
随时随地看视频慕课网APP

相关分类

Java
我要回答