未找到映射(RESOURCE):com / test / hbm / product.hbm.xml:origin(com / test / hbm / product.hbm.xml)
我有2个hbm文件(供应商和客户,但没有产品),但仍显示上述错误(未找到映射(资源):com / test / hbm / product.hbm.xml:origin(com / test / hbm / product .hbm.xml))
这是一个使用休眠的一对多关系程序,在这里我接受了2个供应商和客户类,但是与产品类没有关系,但是当我运行该程序时,我遇到了错误,我在第一行提到的是线程xception。 main” org.hibernate.boot.MappingNotFoundException:找不到映射(RESOURCE):com / test / hbm / product.hbm.xml:origin(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