黑马程序员技术交流社区
标题:
hibernate出现空指针异常,这是为什么啊
[打印本页]
作者:
江南雨
时间:
2013-6-6 08:41
标题:
hibernate出现空指针异常,这是为什么啊
// TODO Auto-generated method stub
Configuration cfg=new Configuration();
cfg.configure();
SessionFactory sf=cfg.buildSessionFactory();
Session session=sf.openSession();
User user=new User();
user.setBirthday(new Date());
user.setId(1);
user.setName("xiaoye");
session.save(user);
session.close();
System.out.println("end")
复制代码
下面是hibernate.cfg.xml配置
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@127.0.0.1:1521:OracleDB</property>
<property name="connection.username">scott</property>
<property name="connection.password">tiger</property>
<property name="dialect">org.hibernate.dialect.Oracle9iDialect</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<mapping resource="com/xiaoye/hibernate/User.hbm.xml"/>
</session-factory>
</hibernat
复制代码
下面是运行结果:这是为什么啊 ?我用的是oracle9i
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:217)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:88)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1834)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1792)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1877)
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