%%%% Error Creating SessionFactory %%%%

  |   0 评论   |   189 浏览

    %%%% Error Creating SessionFactory %%%%
    org.hibernate.MappingException: duplicate property mapping: customer
    at org.hibernate.mapping.PersistentClass.checkPropertyDuplication(PersistentClass.java:414)
    at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:404)
    at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
    at org.hibernate.cfg.Configuration.validate(Configuration.java:984)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1169)
    at com.sily.hib.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:31)
    at com.sily.hib.dao.BaseHibernateDAO.getSession(BaseHibernateDAO.java:15)
    at com.sily.hib.dao.OrdersDAO.saveCustomerAndOrder(OrdersDAO.java:144)
    at com.sily.hib.dao.OrdersDAO.main(OrdersDAO.java:173)
    %%%% Error Creating SessionFactory %%%%
    org.hibernate.MappingException: Could not read mappings from resource: com/sily/hib/po/Usr.hbm.xml
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:485)
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1465)
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1433)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1414)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1390)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1310)
    at com.sily.hib.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:69)
    at com.sily.hib.HibernateSessionFactory.getSession(HibernateSessionFactory.java:53)
    at com.sily.hib.dao.BaseHibernateDAO.getSession(BaseHibernateDAO.java:15)
    at com.sily.hib.dao.OrdersDAO.saveCustomerAndOrder(OrdersDAO.java:144)
    at com.sily.hib.dao.OrdersDAO.main(OrdersDAO.java:173)
    Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping com.sily.hib.po.Usr
    at org.hibernate.cfg.Mappings.addClass(Mappings.java:118)
    at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:154)
    at org.hibernate.cfg.Configuration.add(Configuration.java:386)
    at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:427)
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:482)
    … 10 more
    java.lang.NullPointerException
    at com.sily.hib.dao.OrdersDAO.saveCustomerAndOrder(OrdersDAO.java:146)
    at com.sily.hib.dao.OrdersDAO.main(OrdersDAO.java:173)
    end.

    重复的属性映射关系.报的错是customer,其实不是customer.hbm.xml的配置重复,而是与cumstomer有映射关系的另一个orders.hbm.xml配置中出现了重复,把重复去掉就行了.

    我的问题出现的原因:软件自动生成了映射关系, 而自己还去配置了一个, 所以出错了.出错的时候,是在做一对多的关系,所以说,当时是做的一个customer对应多个orders,在orders.hbm.xml中出现的重复是
    <many-to-one name=“customer” not-null=“true”
    cascade=“all”>
    <column name=“customer_id”></column>
    </many-to-one>
    这个语句写了俩次.去掉一个就行了.我想报的错应该就是红色的标记这个地方.

    评论

    发表评论

    validate