gpt4 book ai didi

java - 无法从资源 Books.hbm.xml 解析映射文档

转载 作者:行者123 更新时间:2023-11-30 08:41:05 24 4
gpt4 key购买 nike

当我尝试使用 hibernate 将对象保存在数据库中时,为什么会出现 hibernate.invalidmappingexception..

books.hbm.xml(资源文件夹内)

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="Books" table="books">
<id name="id">
<generator class="increment"></generator>
</id>
<property name="name"></property>
<property name="author"></property>
<property name="count"></property>
<property name="description"></property>
</class>
</hibernate-mapping>

Hibernate.cfg.xml:

    <hibernate-configuration> 
<session-factory>
<property name="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </property>
<property name="hibernate.connection.driver_class"> com.mysql.jdbc.Driver </property>
<property name="hibernate.connection.url"> jdbc:mysql://localhost/cybage </property>
<property name="hibernate.connection.username"> root </property>
<property name="hibernate.connection.password"> yoga </property>
<mapping resource="Books.hbm.xml"/>
</session-factory>
</hibernate-configuration>

我的项目结构是:

the snapshot of folder structure and files stored...It seems there is something wrong with this

我已将映射文件 BOOKS.hbm.xml 放在资源文件夹中,将 Hibernate.cfg.xml 放在 META/classes 文件夹中

最佳答案

您需要在 books.hbm.xml

中指定带有包的完整类名
<class name="pack.Books" table="books">  

....

</class>

在构建一个 war WEB-INF/classes默认会在类路径下。

classes 文件夹中有 hibernate.cfg.xmluser.hbm.xml — 移动所有 xmlclassesresources

关于java - 无法从资源 Books.hbm.xml 解析映射文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35308512/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com