已解决 | Hibernate MappingNotFoundException

报错信息:

七月 08, 2022 10:39:25 上午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.4.10.Final}
七月 08, 2022 10:39:25 上午 org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead.  Support for obsolete DTD/XSD namespaces may be removed at any time.
七月 08, 2022 10:39:25 上午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
Exception in thread "main" org.hibernate.boot.MappingNotFoundException: Mapping (RESOURCE) not found : com/ai/entity/People.hbm.xml : origin(com/ai/entity/People.hbm.xml)
	at org.hibernate.boot.spi.XmlMappingBinderAccess.bind(XmlMappingBinderAccess.java:56)
	at org.hibernate.boot.MetadataSources.addResource(MetadataSources.java:294)
	at org.hibernate.boot.cfgxml.spi.MappingReference.apply(MappingReference.java:70)
	at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:468)
	at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:84)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:689)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
	at com.ai.test.Test.main(Test.java:11)

.hbm.xml 所在位置:

在这里插入图片描述
要解决这个问题,有两种思路:

1)修改 pom.xml,添加如下代码:

表示允许读取 src/main/java 目录下的 xml 文件

<build>
    <!-- 允许读取src/main/java目录下的xml文件 -->
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
        </resource>
    </resources>
</build>

2)直接将 .hbm.xml 放到 resources 目录下

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值