我是 hibernate 的新手,我在指定 hibernate.cfg.xml 文件中映射文件的位置时遇到了问题。
我在 org.hibernate.tutorial.chapter1.domain.Event.java 包中创建了一个 Event 对象,并在同一位置创建了相应的 Event.hbm.xml 文件。
我试图在 hibernate.cfg.xml 映射标记中指定位置,但我收到 InvalidMappingException ()。
我在帖子中添加了:异常,映射文件和项目文件结构的映射。
任何建议都会很棒。
484 [main] ERROR org.hibernate.util.xml.ErrorLogger - Error parsing XML (1) : cvc-elt.1: Cannot find the declaration of element 'hibernate-mapping'. 495 [main] ERROR org.hibernate.util.xml.ErrorLogger - Error parsing XML (2) : cvc-elt.1: Cannot find the declaration of element 'hibernate-mapping'. Initial SessionFactory creation failed.org.hibernate.InvalidMappingException: Unable to read XML
<!-- Names the annotated entity class -->
<mapping resource="org/hibernate/tutorial/chapter1/domain/Event.hbm.xml"/>
最佳答案
确保在 XML 内容顶部的 Event.hbm.xml 中有 DOCTYPE such as :
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.tutorial.domain">
[...]
</hibernate-mapping>
关于java - Hibernate 的映射问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5574285/