求高手指教运行代码报hibernate.InvalidMappingException: Could not parse mapping document from resource com/hibernate/Person.hbm.xml错误,相关代码如下:
hibernate.cfg.xml文件如下
<!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://127.0.0.1:3306/hibernate_one2one_pk_1</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">111</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<mapping resource="com/hibernate/Person.hbm.xml"/>
<mapping resource="com/hibernate/IdCard.hbm.xml"/>
</session-factory>
</hibernate-configuration>
person.hbm.xml文件如下
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.hibernate.Person" table="t_person">
<id>
<generator class="foreign">
<param name="property">idCard</param>
</generator>
</id>
<property name="name"/>
<one-to-one name="idCard" constrained="true"></one-to-one>
</class>
</hibernate-mapping>
导出数据表ExportDB方法
package com.hibernate;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class ExportDB {
/**
* @param args
*/
public static void main(String[] args) {
Configuration cfg=new Configuration().configure();
SchemaExport export=new SchemaExport(cfg);
export.create(true, true);
}
}
|
|