我做hibernate3.2做测试,做了一个单一实体映射。向数据库导表可以正常导出。可是想在做别的实体类型测试,又做了一个映射文件,就死活也导不出数据库表了!烦死了,弄了一下午我知道是低级问题,可是路径都要没有错误!我第一个映射可以正确导出表,为什么我改了一个映射就导不出去了呢!高手解决下。
下边代码:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- 创建Msql5.0数据库连接方式在Hibernate3.2中 -->
jdbc:mysql://localhost/test
com.mysql.jdbc.Driver
root
root
org.hibernate.dialect.MySQLDialect
<!-- hibernate 自带的数据库连接池 -->
5
20
1800
50
true
true
true
<mapping resource="com/zzz/hibernate/User.hbm.xml"/>
<!-- <mapping resource="com/zzz/hibernate/User1.hbm.xml"/> -->
</session-factory>
User.hbm.xml可以正确导出表,下边那个注释的就死活也导不出去了!
User1.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">
导出表类:
package com.zzz.util;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class ExportDB {
//这是一个导到数据库建表的类;
public static void main(String[] args) {
//读取hibernate.cfg.xml文件;
Configuration cfg=new Configuration().configure();
//读取hibernate 默认hibernate.properies文件;
//Configuration cfg=new Configuration();
SchemaExport export=new SchemaExport(cfg);
export.create(true, true);
}
}
第一个可以通过,注释那个出现这个异常:
Exception in thread "main" org.hibernate.MappingNotFoundException: resource: com/zzz/hibernate/User1.hbm.xml not found