- // 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)
复制代码 |