我在hibernate
中遇到以下异常A
据我所知,我做的每件事都是正确的。但是它仍然显示异常..下面是以下代码。请帮我解决这个问题
student.hbm.xml
这是映射xml文件
Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource student.hbm.xml
hibernate.cfg.xml中 这是confiuration xml文件
<hibernate-mapping>
<class name="com.Student" table="student">
<id name="id" type="int" column="sid">
<generator class="assigned"/>
</id>
<property name="firstName" column="first_name" type="string"/>
<property name="lastName" column="last_name" type="string"/>
</class>
</hibernate-mapping>
这是Student Bean课程 Bean类:Student.java 包com;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<!-- Assume test is the database name -->
<property name="hibernate.connection.url"> jdbc:mysql://localhost:3306/test
</property>
<property name="hibernate.connection.username">
root
</property>
<property name="hibernate.connection.password">
root
</property>
<!-- List of XML mapping files -->
<mapping resource="student.hbm.xml"/>
</session-factory>
</hibernate-configuration>
测试类:Storedata.java 这是Testing类将数据存储到db 包com;
public class Student {
private int id;
private String firstName,lastName;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
上面的代码给出了以下的例外情况
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class Storedata {
public static void main(String[] args) {
//creating configuration object
Configuration cfg=new Configuration();
cfg.configure("hibernate.cfg.xml");//populates the data of the configuration file
SessionFactory factory=cfg.buildSessionFactory();
//creating session object
Session session=factory.openSession();
//creating transaction object
Transaction t=session.beginTransaction();
Student e1=new Student();
// e1.setId(115);
e1.setFirstName("Kiran");
e1.setLastName("raj");
session.save(e1);
t.commit();//transaction is committed
session.close();
System.out.println("successfully saved");
}
}