hibernate配置文件中的标签顺序问题导致报错

本文档详细记录了一个关于hibernate配置文件的问题,由于配置文件中`<property>`标签的位置不正确,导致了`ConfigurationException`。错误信息表明在`hibernate.cfg.xml`中发现了以`<property>`开头的无效内容,应以`<mapping>`, `<class-cache>`, `<collection-cache>`, `<event>`, `<listener>`其中之一开头。解决方案是将`<mapping>`标签移到所有`<property>`标签之后,从而解决了配置文件的解析错误。" 106941172,5995242,自定义PostCSS预处理器:打造个人化的CSS扩展工具,"['前端开发', 'CSS预处理器', 'PostCSS', '插件开发']

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

报错信息

Exception in thread “main” org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number -1 and column -1 in RESOURCE hibernate.cfg.xml. Message: cvc-complex-type.2.4.a: 发现了以元素 ‘{“http://www.hibernate.org/xsd/orm/cfg”:property}’ 开头的无效内容。应以 ‘{“http://www.hibernate.org/xsd/orm/cfg”:mapping, “http://www.hibernate.org/xsd/orm/cfg”:class-cache, “http://www.hibernate.org/xsd/orm/cfg”:collection-cache, “http://www.hibernate.org/xsd/orm/cfg”:event, “http://www.hibernate.org/xsd/orm/cfg”:listener}’ 之一开头。
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:133)
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:65)
at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:57)
at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:165)
at org.hibernate.cfg.Configuration.configure(Configuration.java:258)
at org.hibernate.cfg.Configuration.configure(Configuration.java:244)
at com.hyk.hibernate_day001.Test.main(Test.java:12)
Caused by: javax.xml.bind.UnmarshalException

解决办法

将配置文件hibernate.cfg.xml中的session-factory中的mapping标签放到所有property标签之后。
比如,将

在这里插入图片描述
改为
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值