hibernate总是报空指针是咋回事
hibernate总是报
空指针是怎么回事
public class Student implements java.io.Serializable{
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class Dao {
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
Configuration cfg = new Configuration().configure();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
.applySettings(cfg.getProperties()).buildServiceRegistry();
return cfg.buildSessionFactory(serviceRegistry);
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
Session session = Dao.getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
Student s=new Student();
s.setId(2);
s.setName( admin );
session.save(s);
tx.commit();
session.close();
}
}
?xml version= 1.0 ?
!DOCTYPE hibernate-mapping PUBLIC
-//Hibernate/Hibernate Mapping DTD 3.0//EN
hibernate-mapping package= org.hibernate.tutorial.domain
class name= entity.Student table= student
id name= id /id
property name= name /property
/class
/hibernate-mapping
?xml version='1.0' encoding='utf-8'?
!DOCTYPE hibernate-configuration PUBLIC
-//Hibernate/Hibernate Configuration DTD 3.0//EN
hibernate-configuration
session-factory
!-- Database connection settings --
property name= connection.driver_class oracle.jdbc.driver.OracleDriver /property
property name= connection.url jdbc:oracle:thin:@localhost:1521:orcl /property
property name= connection.username zhxl /property
property name= connection.password zhxl /property
!-- SQL dialect --
property name= dialect org.hibernate.dialect.Oracle10gDialect /property
!-- Disable the second-level cache --
property name= cache.provider_class org.hibernate.cache.NoCacheProvider
/property
!-- Echo all executed SQL to stdout --
property name= show_sql true /property
!-- Drop and re-create the database schema on startup --
property name= hbm2ddl.auto update /property
mapping resource= entity/Student.hbm.xml /
/session-factory
/hibernate-configuration
不知道为什么总报空指针
2012-11-8 16:00:30 org.hibernate.annotations.common.Version clinit
本文档为【hibernate总是报空指针是咋回事】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。