Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource hh/qq/Student.hbm.xml
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3360)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXmlQueue(Configuration.java:3349)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3337)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1322)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1712)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1761)
at Strudent_Test.main(Strudent_Test.java:16)
Caused by: org.hibernate.MappingException: class hh.qq.Students.Students not found while looking for property: id
at org.hibernate.internal.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:231)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:313)
at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:448)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:381)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:323)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:174)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3357)
... 6 more
Caused by: java.lang.ClassNotFoundException: hh.qq.Students.Students
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.hibernate.internal.util.ReflectHelper.classForName(ReflectHelper.java:191)
at org.hibernate.internal.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:227)
... 12 more
hibernate的配置:<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"><hibernate-configuration>    <session-factory>        <!-- Database connection settings -->
        <property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
        <property name="connection.url">jdbc:sqlserver://localhost:1433/TestStudents</property>
        <property name="connection.username">sa</property>
        <property name="connection.password">huhai</property>        <!-- JDBC connection pool (use the built-in)-->
       <!-- <property name="connection.pool_size">1</property> -->        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.SQLServer2005Dialect</property>        <!-- Enable Hibernate's automatic session context management -->
        <!-- <property name="current_session_context_class">thread</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="hh/qq/Student.hbm.xml"/>    </session-factory></hibernate-configuration>
映射文件的配置:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"><hibernate-mapping package="hh.qq.Students">
<class name="Students" table="Student">
<id name="id"></id>
<property name="name"></property>
<property name="birthday"></property>
</class>
</hibernate-mapping>

解决方案 »

  1.   

    Caused by: java.lang.ClassNotFoundException: hh.qq.Students.Students
     找不到hh.qq.Students的Students这个类<hibernate-mapping package="hh.qq.Students">
     <class name="Students" table="Student">
    看你的路径对不
     
      

  2.   

    hh.qq.Students.Students
    是不是
    应该hh.qq.Students <hibernate-mapping package="hh.qq.Students">
    -->
    <hibernate-mapping package="hh.qq">
      

  3.   

    ERROR: HHH000197: Error parsing XML: /hibernate.cfg.xml(34) Open quote is expected for attribute "{1}" associated with an  element type  "resource".
    Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1996)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1908)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1887)
    at Strudent_Test.main(Strudent_Test.java:16)
    Caused by: org.dom4j.DocumentException: Error on line 34 of document  : Open quote is expected for attribute "{1}" associated with an  element type  "resource". Nested exception: Open quote is expected for attribute "{1}" associated with an  element type  "resource".
    at org.dom4j.io.SAXReader.read(SAXReader.java:482)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1988)
      

  4.   

    Exception in thread "main" org.hibernate.MappingNotFoundException: resource: Hibernate_Test/src/hh/qq/Student.hbm.xml not found
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:723)
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2088)
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2060)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2040)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1993)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1908)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1887)
    at Strudent_Test.main(Strudent_Test.java:16)