前辈们好!
    我刚刚学习使用hibernate,关于配置文件的路径问题有些不明白!
    我在执行HibernateTest.java文件中这条语句时出现错误:
    Configuration config = new Configuration().configure();
    错误信息如下:
    2009-01-28 13:39:14,015 INFO org.hibernate.cfg.Environment[main] - Hibernate 3.2.6
    Exception in thread "main" java.lang.ExceptionInInitializerError
at org.hibernate.cfg.Configuration.reset(Configuration.java:174)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:193)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:197)
at mapping.HibernateTest.main(HibernateTest.java:10)
   Caused by: java.lang.NullPointerException
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:144)
at org.hibernate.cfg.Environment.<clinit>(Environment.java:529)
... 4 more我怀疑是没有读取到配置文件.我的配置文件路径如下:
        我在eclipse中建里一个ejb project,ejbModule下有一个sessionbean packge里面放了几个sessionbean.
        然后再ejbModule下还有一个mapping packge和sessionbean packge是平级的.
        在mapping packge里面有:
          HibernateTest.java
          user.java(对应数据库表的pojo文件)
          user.hbm.xml(映射文件)
        在ejbModule下面还有一个hibernate的配置文件:hibernate.cfg.xml 和前面2个packge是平级的.我运行HibernateTest.java文件进行测试的时候就报上面的错误!请您指点一二,感激不尽!
       
       hibernate.cfg.xml文件内容如下:      <?xml version="1.0" encoding="utf-8"?>
      <!DOCTYPE hibernate-configuration
       PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
       "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">      <hibernate-configuration>
        <session-factory name="hibernate" > <!-- local connection properties -->
<property  name="hibernate.connection.url">jdbc:mysql://localhost:3306/wukuang_stock</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">12345</property>
<!-- property name="hibernate.connection.pool_size"></property --> <!-- dialect for MySQL -->
                <property name="dialect">org.hibernate.dialect.MySQLDialect</property>                <property name="hibernate.show_sql">true</property>
                <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
               <mapping resource="mapping/User.hbm.xml"/>
      
        </session-factory>
     </hibernate-configuration>user.hbm.xml文件内容如下:<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" ><hibernate-mapping package="mapping">
<class
name="user"
table="user"
>
<meta attribute="sync-DAO">false</meta>
<id
name="Id"
type="integer"
column="id"
>
<generator class="sequence"/>
</id> <property
name="Name"
column="name"
type="string"
not-null="true"
length="45"
/>
<property
name="Sex"
column="sex"
type="integer"
not-null="true"
length="10"
/>
<property
name="IdCard"
column="id_card"
type="integer"
not-null="true"
length="10"
/>
<property
name="Tel"
column="tel"
type="string"
not-null="true"
length="45"
/>
<property
name="Mobile"
column="mobile"
type="integer"
not-null="true"
length="10"
/>
<property
name="Fax"
column="fax"
type="string"
not-null="true"
length="45"
/>
<property
name="Address"
column="address"
type="string"
not-null="true"
length="45"
/>
<property
name="GruopType"
column="gruop_type"
type="integer"
not-null="true"
length="10"
/>
</class>
</hibernate-mapping>
        

解决方案 »

  1.   

    LZ可以去GOOGLE上搜“at org.hibernate.cfg.Configuration.reset(Configuration.java:174)”  会搜出几篇关于此类问题的问题及解决办法...  你可以试一下
      

  2.   

    如果这样写:Configuration config = new Configuration().configure(); 要确保hibernate.cfg.xml放在classpath的根下,如果放在某个包下,要加上报名:Configuration config = new Configuration().configure("包名/hibernate.cfg.xml"); 
      

  3.   

    我在eclipse里面建立一个ejb project的时候EjbMoudle文件夹是它自动生成的,可是部署到jboss之后这个文件夹是不存在的,它先面的所有包都是在jar文件的最外层.我搞不清楚classpath到底是哪个路径!我应该放把hibernate.cfg.xml放在哪里!
      

  4.   

    把hibernate.cfg.xml放在源文件夹下。一般默认是src,比如在src文件夹下有com.test.xxx包那么发布过去后,会在classes里面出现com.test.xxx包源文件夹对应classes目录(也就是classpath)
      

  5.   

    hibernate.cfg.xml要放到源码根目录下
    否则在configure时得指定路径
      

  6.   

    把hibernate.cfg.xml放在classes文件夹下
      

  7.   

    HibernateTest.java  这个代码贴出来看看。。
    好像是你这个主程序初始化的时候出的错。