org.hibernate.boot.MappingNotFoundException Mapping (RESOURCE) не найден: com / test / hbm / product.hbm.xml: origin (com / test / hbm / product.hbm.xml) - PullRequest
0 голосов
/ 14 января 2019

Сопоставление (RESOURCE) не найдено: com / test / hbm / product.hbm.xml: происхождение (com / test / hbm / product.hbm.xml)

У меня есть 2 файла hbm (Поставщик и Клиент, но без Продукта), но все еще отображается ошибка выше (Сопоставление (RESOURCE) не найдено: com / test / hbm / product.hbm.xml: origin (com / test / hbm / product) .hbm.xml))

Это программа отношений один-ко-многим, использующая hibernate, здесь я взял 2 класса Vendor и Customer, но не имею отношения к классу продукта, но когда я запускаю программу, я получаю сообщение об ошибке, о которой я упоминаю в первой строке, что это xception in thread » main "org.hibernate.boot.MappingNotFoundException: сопоставление (RESOURCE) не найдено: com / test / hbm / product.hbm.xml: происхождение (com / test / hbm / product.hbm.xml)

     *****   vendor.hbm.xml*********

        <?xml version="1.0" encoding="UTF-8"?>

        <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.org/dtd/hibernate-mapping-3.0.dtd">

        <hibernate-mapping>

        <class name="com.test.model.Vendor" table="VENDOR">

             <id name="vendorId" type="int" column="VID"></id>
             <property name="vendorName" type="String" column="VNAME"></property>

             <set name="children" cascade="all">

                <key column="forevenId"></key>
                <one-to-many class="com.test.model.Customer"/>

             </set>     

        </class>


        </hibernate-mapping>

          ********  customer.hbm.xml  *************

            <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.org/dtd/hibernate-mapping-3.0.dtd">

        <hibernate-mapping>

        <class name="com.test.model.Customer" table="CUSTOMER">
             <id name="customerId" column="CID" type="int"></id>
             <property name="customerName" column="CNAME" type="String"></property>
             <property name="forevenId" column="FID " type="int" insert="false"></property>         
        </class>


        </hibernate-mapping>


********    hibernate.cfg.xml  **********

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

    <hibernate-configuration>
        <session-factory>

            <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
            <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
            <property name="hibernate.connection.password">root</property>
            <property name="hibernate.connection.username">root</property>
            <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
            <property name="show_sql">true</property>
            <property name="hbm2ddl.auto">update</property>
            <!-- <mapping class="com.test.model.Student"></mapping> -->

            <mapping resource="com/test/hbm/customer.hbm.xml"/>
            <mapping resource="com/test/hbm/vendor.hbm.xml"/>


        </session-factory>
    </hibernate-configuration>



    Customer.java


    package com.test.model;

    public class Customer {

        private int customerId;
        private String customerName;
        private int forevenId;

        public int getCustomerId() {
            return customerId;
        }
        public void setCustomerId(int customerId) {
            this.customerId = customerId;
        }
        public String getCustomerName() {
            return customerName;
        }
        public void setCustomerName(String customerName) {
            this.customerName = customerName;
        }
        public int getForevenId() {
            return forevenId;
        }
        public void setForevenId(int forevenId) {
            this.forevenId = forevenId;
        }



    }



    Vendor.java

    package com.test.model;

    import java.util.Set;

    public class Vendor {

        private int vendorId;
        private String vendorName;
        private Set children;

        public int getVendorId() {
            return vendorId;
        }
        public void setVendorId(int vendorId) {
            this.vendorId = vendorId;
        }
        public String getVendorName() {
            return vendorName;
        }
        public void setVendorName(String vendorName) {
            this.vendorName = vendorName;
        }
        public Set getChildren() {
            return children;
        }
        public void setChildren(Set children) {
            this.children = children;
        }



    }


    Client.java


    package com.test.client;

    import java.util.HashSet;
    import java.util.Set;

    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.Transaction;
    import org.hibernate.cfg.Configuration;

    import com.test.model.Customer;
    import com.test.model.Vendor;

    public class Client {

        public static void main(String[] args) {


            Configuration conf=new Configuration();
            conf.configure("/com/test/cfg/hibernate.cfg.xml");
            SessionFactory factory=conf.buildSessionFactory();

            Session session=factory.openSession();

            Vendor v=new Vendor();
            v.setVendorId(101);
            v.setVendorName("Honda");

            Customer c1=new Customer();
            c1.setCustomerId(901);
            c1.setCustomerName("customer5");

            Customer c2=new Customer();
            c2.setCustomerId(902);
            c2.setCustomerName("customer6");

            Customer c3=new Customer();
            c3.setCustomerId(903);
            c3.setCustomerName("customer7");

            Set s=new HashSet();
            s.add(c1);
            s.add(c2);
            s.add(c3);

            v.setChildren(s);

            Transaction tx=session.beginTransaction();

            session.save(v);

            tx.commit();

            session.close();
            System.out.println("One to Many is done");
            factory.close();

        }


    }

    there is no any relation with product class
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...