Java 无法分析resource Books.hbm.xml中的映射文档
当我尝试使用hibernate在数据库中保存对象时,为什么会出现hibernate.invalidmappingexception books.hbm.xml(在资源文件夹中)Java 无法分析resource Books.hbm.xml中的映射文档,java,hibernate,Java,Hibernate,当我尝试使用hibernate在数据库中保存对象时,为什么会出现hibernate.invalidmappingexception books.hbm.xml(在资源文件夹中) Hibernate.cfg.xml: org.hibernate.dialogue.mysqldialogue com.mysql.jdbc.Driver jdbc:mysql://localhost/cybage 根 瑜伽 我的项目结构是: 我已将映射文件BOOKS.hbm.xml放在资源文件夹中,将Hi
Hibernate.cfg.xml:
org.hibernate.dialogue.mysqldialogue
com.mysql.jdbc.Driver
jdbc:mysql://localhost/cybage
根
瑜伽
我的项目结构是:
我已将映射文件BOOKS.hbm.xml放在资源文件夹中,将Hibernate.cfg.xml放在META/classes文件夹中,请尝试替换此文件:
<mapping resource="Books.hbm.xml"/>
与:
添加正确的路径。您需要在Hibernate.cfg.xml中提供hbm文件的正确映射路径 所以只要换成
<mapping resource="resources/Books.hbm.xml"/>
因为您的hbm文件位于resources文件夹中,所以您需要提供相同的路径。您需要在
books.hbm.xml
<class name="pack.Books" table="books">
....
</class>
....
在构建war
之后,您需要将resources
文件夹放在main
文件夹中,才能将所有文件放在WEB-INF/classes
中<默认情况下,代码>WEB-INF/classes将位于类路径中
您在
classes
文件夹中有hibernate.cfg.xml
和user.hbm.xml
-将所有xml
从classes
移动到资源尝试发布您的文件hibernate配置post your hibernate.cfg.hibernate.dial.mysqldial>com.mysql.jdbc.Driver jdbc:mysql://localhost/cybage 请添加完整的堆栈跟踪,并将其添加到答案中,而不是添加到注释中。如果他使用有效的maven构建,则资源
将在构建后位于WEB-INF/classes
中。
<mapping resource="resources/Books.hbm.xml"/>
<mapping resource="resources/Books.hbm.xml"/>
<class name="pack.Books" table="books">
....
</class>