net.sf.hibernate.MappingException: Resource: net sf hibernate example quickstart Cat.hbm.xml not found这个问题怎么办啊?字面理解是XML位置不对,
没被HIBERNATE读取。可我的目录结构是正确的啊。
这是我的类:
package net.sf.hibernate.example.quickstart;
public class Cat {
private String id;
private String name;
private char sex;
private float weight;
只有简单的4个字段,下面是getter和setter方法。
这是我的这个Cat类的映射xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="net.sf.hibernate.example.quickstart.Cat" table="cat">
<id name="id" type="string" unsaved-value="null">
<column name="CAT_ID" sql-type="varchar(32)" not-null="true" />
<generator class="uuid.hex"/>
</id>
<property name="name">
<column="name" sql-type="varchar(16)" not-null="true"/>
</property>
<property name="sex"/>
<property name="weight"/>
</class>
</hibernate-mapping>
这个XML和类文件放在同一个目录下面了。
hibernate.cfg.xml放在classes目录下面。内容为:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="dialect">net.sf.hibernate.dialect.SQLServerDialect</property>
<property name="connection.datasource">java:comp/env/jdbc/quickstart</property>
<property name="jdbc.fetch_size">50</property>
<property name="jdbc.batch_size">30</property>
<property name="show_sql">true</property>
<!-- Mapping files -->
<mapping resource="Cat.hbm.xml"/>
</session-factory>
</hibernate-configuration>
然后我TOMCAT配置了一个应该的数据连接池。也写了个应用类:
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.example.quickstart.Cat;
public class insertCat {
private static Session session;
private static Transaction tx;
static{
try{
session = HibernateUtil.currentSession();
tx = session.beginTransaction();
}catch(Exception e){