日期:2014-05-19 浏览次数:20728 次
//这是id-card的映射文件 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="demo01"> <class name="id_card"> <id name="id"> <generator class="native" /> </id> <property name="name" /> <one-to-one name="Person" /> <!-- 创建一对一映射 --> </class> </hibernate-mapping>
//这是id-card类实例 package demo01; public class id_card { private int id; private String name; private Person per; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Person getPer() { return per; } public void setPer(Person per) { this.per = per; } }
//这是配置文件 <?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"> <!-- Generated by MyEclipse Hibernate Tools. --> <hibernate-configuration> <session-factory> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="connection.url">jdbc:mysql://localhost:3306/data_01</property> <property name="connection.username">root</property> <property name="connection.password">mysqladmin</property> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="myeclipse.connection.profile">MyEclipse Derby</property> <property name="show_sql">true</property> <property name="hbm2ddl.auto">create</property> <mapping resource="DAO_/User.bhm.xml" /> <mapping resource="DAO_/School.bhm.xml" /> <mapping resource="DAO_/Student.bhm.xml" /> <mapping resource="demo01/Person.bhm.xml" /> <mapping resource="demo01/id_card.bhm.xml" /> </session-factory> </hibernate-configuration>
下面是报告的异常 说无法从配置文件 初始化id_card的映射 Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource demo01/id
<?xml version="1.0" encoding="utf-8"?> <!-- 映射文件需要指定格式 --> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"