做hibernate的代码测试,看不懂错误,请高手帮我看下!
旁边Failure Trace有什么错误
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="connection.username">root</property> <property name="connection.password">mysql</property> <property name="connection.driver_class">com.mysql/jdbc.Driver</property> <property name="connection.url">jdbc:mysql:///hibernate?userUnicode=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"create></property> <mapping resource="Students.hbm.xml"/> </session-factory> </hibernate-configuration>
package hibernate; import java.util.Date; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistryBuilder; import org.junit.After; import org.junit.Before; import org.junit.Test; public class StudentTest { private SessionFactory sessionFactory; private org.hibernate.Session session; private org.hibernate.Transaction transaction; @Before public void init(){ //创建配置对象 Configuration config =new Configuration().configure(); //创建服务注册对象 ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry(); //创建会话工厂对象 sessionFactory = config.buildSessionFactory(serviceRegistry); //会话对象 session = sessionFactory.openSession(); //开启事务 transaction = session.beginTransaction(); } @After public void destory(){ transaction.commit();//提交事务 session.close();//关闭回话 sessionFactory.close();//关闭会话工厂 } @Test public void testSaveStudents(){ //生成学生对象 Students s=new Students(1,"张三丰","男",new Date(),"武当山"); session.save(s);//保存对象进数据库 } }
哦!不是28是41行
28行有个空指针,,25行的那个不知道
能发一下代码吗
这个是Failure Trace