Hibernate无效的配置映射


大家早上好!我试图使用Hibernate在Java中使用Eclipse读取MSAccess数据库,但它给了我一个MappingException

这是我的hibernateaccess.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping SYSTEM
    "classpath://org/hibernate/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <session-factory>
        <property name='connection.driver_class'>net.ucanaccess.jdbc.UcanaccessDriver</property>
        <property name='connection.username'></property>
        <property name='connection.password'></property>
        <!-- JDBC connection pool (use the built-in) -->
        <property name='connection.pool_size'>1000</property>
        <property name="hibernate.c3p0.min_size">2</property>
        <property name="hibernate.c3p0.max_size">600000</property>
        <!-- SQL dialect -->
        <property name='dialect'>dialect.MSAccessDialect</property>
        <!-- Echo all executed SQL to stdout -->
        <property name='show_sql'>true</property>
        <!-- Mapping files -->
        <mapping class="TransporteAccess.hbm.xml" />
    </session-factory>
</hibernate-mapping>

和TransporteAccess.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping SYSTEM
    "classpath://org/hibernate/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="model.Transporte" table="Transportes">
        <property name="transporte" column="TRANSPORTES" type="string"></property>
    </class>
</hibernate-mapping>

我做错了什么??非常感谢!

在Hibernate中必须有主键,参见同时添加主键

<id name="id" type="int" column="id">
    <generator class="native"/>
</id>

除此之外,hibernateaccess.xml包含一些不相关的标签

更新hibernateaccess.xml的顶行
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>

,把

<mapping class="TransporteAccess.hbm.xml" />

<mapping resource="TransporteAccess.hbm.xml" />

最新更新