【问题标题】:Hibernate invalid configuration mappingHibernate 无效的配置映射
【发布时间】:2016-11-14 10:36:46
【问题描述】:

大家早上好! 我正在尝试使用 Hibernate 使用 Eclipse 读取 Java 中的 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>

我做错了吗??? 非常感谢!

【问题讨论】:

    标签: java hibernate ms-access


    【解决方案1】:

    Hibernate 中必须有主键,refer 也添加主键,

    <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" />
    

    【讨论】:

    • 但是该表没有主键(它是一个没有信息人制作的旧数据库)
    • 只需添加具有默认行为的默认主键,因为没有主键休眠将无法工作
    • 添加但不工作,我认为错误来自 Hibernateaccess.cfg.xml,因为如果我评论 错误仍然发生跨度>
    • 最初它抛出了问题中提到的 MappingException!
    • 这是异常信息:HHH000040:配置资源:hibernateaccess.cfg.xml 初始会话工厂创建失败。org.hibernate.MappingException:无效配置
    猜你喜欢
    • 2015-12-03
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多