Hibernate4 SessionFactory 空指针

Configuration conf = new Configuration().configure();
StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder().applySettings(conf.getProperties());
StandardServiceRegistry sr = srb.build();
SessionFactory sf = conf.buildSessionFactory(sr);

    上面这样写有问题吗,为什么老是报空指针异常


    配置文件
    <session-factory>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">1991</property>
    <property name="hibernate.c3p0.max_size">20</property>
    <property name="hibernate.c3p0.min_size">1</property>
    <property name="hibernate.c3p0.timeout">5000</property>
    <property name="hibernate.c3p0.max_statements">100</property>
    <property name="hibernate.c3p0.idle_test_period">3000</property>
    <property name="hibernate.c3p0.acquire_increment">2</property>
    <property name="hibernate.c3p0.validate">true</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
    <property name="hbm2ddl.auto">update</property>
    <property name="show_sql">true</property>        
   <property name="hibernate.format_sql">true</property>
    <mapping class="org.zmf.hibernate.entity.ReAddress"/>
    <mapping class="org.zmf.hibernate.entity.Users"/>
    <mapping class="org.zmf.hibernate.entity.News"/>
</session-factory>

StandardServiceRegistry sr = srb.build();
改成
ServiceRegistry sr = srb.build();
试试

检查下,可能是配置文件的问题

我搞好了,是因为有一个实体的外键写错了,

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity(name="readdress")
public class ReAddress{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id;
private String rename;
public ReAddress() {

}
public ReAddress(String rename) {

    this.rename = rename;
}
public Integer getId() {
    return id;
}
public void setId(Integer id) {
    this.id = id;
}
public String getRename() {
    return rename;
}
public void setRename(String rename) {
    this.rename = rename;
}

}
能帮我看看这个写的有什么问题吗,不能创建表