《后端》报错:People.hbm.xml这个映射找不到和空指针异常--2021-01-12

博客主要围绕两个问题展开。一是com/bella/entity/People.hbm.xml映射找不到,原因可能是代码错误或位置问题,解决办法是在pom文件添加设置让java能读到xml文件;二是提到了空指针异常(NullPointerException)。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

com/bella/entity/People.hbm.xml这个映射找不到

代码没写错,但是报错如下:

Exception in thread "main" org.hibernate.MappingNotFoundException: resource: com/bella/entity/People.hbm.xml not found
	at org.hibernate.cfg.Configuration.addResource(Configuration.java:731)
	at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2125)
	at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2097)
	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2077)
	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2030)
	at org.hibernate.cfg.Configuration.configure(Configuration.java:1945)
	at org.hibernate.cfg.Configuration.configure(Configuration.java:1924)
	at test.test.main(test.java:11)

意思是com/bella/entity/People.hbm.xml这个映射找不到。

原因:有两种,一是代码写错,而是位置问题导致找不到。

idea工程中,在java文件中读不到想xml文件。

解决:在pom文件中添加设置,使其能在java中读到xml文件。

   <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                        <include>**/*.xml</include>
                    </includes>
            </resource>
        </resources>
    </build>

 

空指针异常:NullPointerException

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值