Document root element "hibernate-mapping", must match DOCTYPE root "hibernate-configuration
报错信息为:Caused by: org.hibernate.boot.InvalidMappingException: Could not parse mapping document: com/imooc/entity/Grade.hbm.xml (RESOURCE)
如果运行后在console中会有如下的报错,就是找不到我们要的映射文件。是我们的映射文件出错了。
所以我们要打开查看我们的映射文件。
在打开Grade.hbm.xml后,在代码部分(source)是找不到报错的,但是在design部分,会看见报错。主要就是找不到hibernate-mapping部分报错如下:
如何解决:
Document root element "hibernate-mapping", must match DOCTYPE root "hibernate-configuration的问题?
那么出错的原因是什么呢?
是因为xml中的头部信息,不仔细看根本看不出来,
一般如果不自动生成的话,就是直接复制hibernate.cfg.xml的头部信息,所以把hibernate-configuration也复制了过来,改成hibernate-mapping就可以了。
这张是改前:
这张是改后:
Document root element "hibernate-mapping", must match DOCTYPE root "hibernate-configuration可以解决了。
此处显示成功解决了映射问题的错误。
如果自动生成映射文件?
参考:https://blog.****.net/woshirongshaolin/article/details/7861906