把你的这个Teacher.hbm.xml
文件贴出来,这里有错误。hibernate.cfg.xml中有对这个的引用,最终导致不能建立sessionFactory

解决方案 »

  1.   

    不像是xml文件错误哪个加载其他xml映射文件都会出错
    这是HibernateUtil.java
    configuration = new Configuration();
    sessionFactory = configuration.configure().buildSessionFactory();
    configuration
    .addClass(Teacher.class)
    Teacher.hbm.xml
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
                                "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
                                "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" ><!-- DO NOT EDIT: This is a generated file that is synchronized -->
    <!-- by MyEclipse Hibernate tool integration.                   -->
    <!-- Created Sat Nov 19 16:56:12 CST 2005                         -->
    <hibernate-mapping package="com.homework.hibernate">    <class name="Teacher" table="Teacher">
            <id name="teacherid" column="teacherID" type="java.lang.String">
                <generator class="assigned"/>
            </id>
     
            <property name="name" column="name" type="java.lang.String"  not-null="true" />
            <property name="password" column="password" type="java.lang.String"  not-null="true" />
        </class>
        
    </hibernate-mapping>
      

  2.   

    configuration = new Configuration();
    sessionFactory = configuration.configure().buildSessionFactory();
    configuration
    .addClass(Teacher.class)
    哦,如果你用的是.xml格式的配置文件(我指的是hibernate.cfg.xml),那么就不需要
    configuration.addClass(Teacher.class)
    如果是.properties格式的配置文件,则需要,configuration = new Configuration();
    configuration.addClass(Teacher.class);
    sessionFactory = configuration.configure().buildSessionFactory();但是你的顺序不对。
      

  3.   

    还是不行啊.要是后者的话是不是就先装载xml再根据hbm.xml建立sessionFactory
    改了之后还是抛出哪个异常.
      

  4.   

    Initial SessionFactory creation failed.net.sf.hibernate.MappingException: Error reading resource: com/homework/hibernate/Teacher.hbm.xml
    能确定映射文件和pojo都在这个目录下吗?
      

  5.   

    你有几个xml文件,是只有这一个吗?
    你的hibernate是2.X的?
      

  6.   

    没错啊,pojo和hbm.xml文件是在一起的,我得用的是myeclipse,已经不在tomcat下部署好了啊,路径没有问题
      

  7.   

    Teacher.hbm.xml在hibernate.cfg.xml中,把这个类的映射文件先去掉,再运行,看可以不?把问题定位到具体的地方!
      

  8.   

    我有多个hbm.xml映射文件,哪个放在前面都不行,都是同一个异常,读取XX.hbm.xml文件有误,郁闷死了.不知是在哪配置的事?谁遇见过这问题?
      

  9.   

    你把所有的<mapping resource="XXX.hbm.xml"/>
    这些全部删除,直接获得sessionfactory看看是否出错
      

  10.   

    <mapping resource="XXX.hbm.xml"/>作为hibernate.cfg.xml文件必需的元素是不能够删除的吧
    否则解析会出错的?
      

  11.   

    是不是这样,在xml进行配置时,不需要addClass();方法了
    sessionFactory = configuration.configure()就以经装载了所有的xml映射配置文件了
    哪位懂得人来指点一下
      

  12.   

    我看, 最有可能是,  你的classpath 没有设对。  这样, 就没有找到你的Hibernate映射文件。
      

  13.   

    还是楼上说的对, classpath没有设置正确。 他找不到那个配置文件哦