log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
%%%% Error Creating SessionFactory %%%%
org.hibernate.MappingException: An association from the table t_orders refers to an unmapped class: hibenate.model.Customer
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1252)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1170)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
at hibernate.hibernateSessionFactory.<clinit>(hibernateSessionFactory.java:26)
at test.main(test.java:13)
%%%% Error Creating SessionFactory %%%%
org.hibernate.InvalidMappingException: Could not parse mapping document from resource hibernate/orm/Customer.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:569)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
at hibernate.hibernateSessionFactory.rebuildSessionFactory(hibernateSessionFactory.java:62)
at hibernate.hibernateSessionFactory.getSession(hibernateSessionFactory.java:47)
at test.main(test.java:13)
Caused by: org.hibernate.DuplicateMappingException: Duplicate collection role mapping hibernate.model.Customer.orders
at org.hibernate.cfg.Mappings.addCollection(Mappings.java:124)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2066)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2041)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:359)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:273)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:144)
at org.hibernate.cfg.Configuration.add(Configuration.java:669)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:504)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:566)
... 8 more
Exception in thread "main" java.lang.NullPointerException
at test.main(test.java:14)

解决方案 »

  1.   

    <hibernate-configuration>
        <session-factory name="hibernateSessionFactory">
            <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
            <property name="hibernate.connection.password">19861126</property>
            <property name="hibernate.connection.url">jdbc:mysql://localhost:8080/webdb?characterEncoding=UTF-8</property>
            <property name="hibernate.connection.username">root</property>
            <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>        <mapping resource="hibernate/orm/Customer.hbm.xml"></mapping>
            <mapping resource="hibernate/orm/Order.hbm.xml"></mapping>
       
        </session-factory><hibernate-mapping>
    <class name="hibernate.model.Customer" table="t_customers" catalog="webdb">
    <id name="id" column="id" type="int">
    <generator class="increment" />
    </id>
    <property name="name" column="name" type="string" />
     
    <set  name="orders" cascade="save-update,delete" inverse="true" 
    order-by="order_number asc" lazy="true">
    <key column="customer_id" />
    <one-to-many class="hibernate.model.Order" />
    </set>
    </class>      
    </hibernate-mapping>
    <hibernate-mapping>
    <class name="hibernate.model.Order" table="t_orders" catalog="webdb">
    <id name="id" column="id" type="int">
    <generator class="increment" />
    </id>
    <property name="number" column="order_number" type="string" />
    <many-to-one name="customer" column="customer_id"  
    class="hibenate.model.Customer"
    cascade="save-update" > 
    </many-to-one>
    </class>
    </hibernate-mapping>
      

  2.   

    An association from the table t_orders refers to an unmapped class: hibenate.model.Customer
    都告诉你错误在哪里了.映射的类在哪里,存在不,用IDE检查下你的HBM.XML文件对不
      

  3.   

    映射的类在hibernate.model目录
    而且hbm.xml文件validate都未出错
      

  4.   

    <many-to-one name="customer" column="customer_id"   
    class="hibenate.model.Customer"
    cascade="save-update" >  
    </many-to-one>
    hibernate.model.Customer写错了
      

  5.   

    不公是这一个地方还有一个hibernate.cfg.xml中的一些设置被我简化了
        <session-factory name="hibernateSessionFactory">
            <property name="connection.username">root</property>
    <property name="connection.url">
    jdbc:mysql://localhost/webdb?characterEncoding=UTF8
    </property>
    <property name="dialect">
    org.hibernate.dialect.MySQLDialect
    </property>
    <property name="cache.use_query_cache">true</property>
    <property name="cache.provider_class">
    org.hibernate.cache.HashtableCacheProvider
    </property>

    <property name="show_sql">true</property>
    <property name="connection.password">19861126</property>
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>        <mapping resource="hibernate/orm/Customer.hbm.xml"></mapping>
            <mapping resource="hibernate/orm/Order.hbm.xml"></mapping>
         
          
        
        
        </session-factory>
        
    出现了数据库拒绝被访问,不过被我也给解决了
      

  6.   

    An association from the table t_orders refers to an unmapped class: hibenate.model.Customer
    hbm.xml文件有问题吧...
      

  7.   

    An association from the table t_orders refers to an unmapped class: hibenate.model.Customer
    关联到实体类Customer时出错,检查下