黑马程序员技术交流社区

标题: hibernate出现空指针异常,这是为什么啊 [打印本页]

作者: 江南雨    时间: 2013-6-6 08:41
标题: hibernate出现空指针异常,这是为什么啊
  1.         // TODO Auto-generated method stub
  2.                 Configuration cfg=new Configuration();
  3.                 cfg.configure();
  4.                 SessionFactory sf=cfg.buildSessionFactory();
  5.                 Session session=sf.openSession();
  6.                 User user=new User();
  7.                 user.setBirthday(new Date());
  8.                 user.setId(1);
  9.                 user.setName("xiaoye");
  10.                 session.save(user);
  11.                 session.close();
  12.                 System.out.println("end")
复制代码
下面是hibernate.cfg.xml配置
  1. <!DOCTYPE hibernate-configuration PUBLIC
  2.         "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  3.         "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

  4. <hibernate-configuration>
  5.         <session-factory>
  6.                 <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
  7.                 <property name="connection.url">jdbc:oracle:thin:@127.0.0.1:1521:OracleDB</property>
  8.                 <property name="connection.username">scott</property>
  9.                 <property name="connection.password">tiger</property>
  10.                 <property name="dialect">org.hibernate.dialect.Oracle9iDialect</property>
  11.                 <property name="hibernate.hbm2ddl.auto">create</property>
  12.                 <mapping resource="com/xiaoye/hibernate/User.hbm.xml"/>
  13.         </session-factory>
  14. </hibernat
复制代码
下面是运行结果:这是为什么啊 ?我用的是oracle9i
  1. Exception in thread "main" java.lang.NullPointerException
  2.         at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:217)
  3.         at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:88)
  4.         at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
  5.         at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
  6.         at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1834)
  7.         at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1792)
  8.         at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1877)
  9.         at com.xiaoye.test.Test.main(Test.java:21)
复制代码

作者: 张歆明    时间: 2013-6-7 00:46
能不能把你的这个项目的所有文件贴出来 我看看 还有 Hibernate的数据库操作要基于事务  你的事务开启和提交要写上 确保操作的正确性
作者: 孙百鑫    时间: 2013-6-15 07:20
楼主您好如果问题得到解决的话.请修改主题分楼哦




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2