本文介绍了Hibernate的映射问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是hibernate的新用户,我在hibernate.cfg.xml文件中指定映射文件的位置时遇到问题。

I am new to hibernate and i am having trouble with specifying the location of the mapping file in hibernate.cfg.xml file.

我创建了一个Event对象在org.hibernate.tutorial.chapter1.domain.Event.java包中,其对应的Event.hbm.xml文件在同一位置。

I have created an Event object in org.hibernate.tutorial.chapter1.domain.Event.java package with its corresponding Event.hbm.xml file in the same location.

我试图指定位置在hibernate.cfg.xml映射标记,但我得到一个InvalidMappingException()。

I am trying to specify the location in the hibernate.cfg.xml mapping tag but I am getting an InvalidMappingException ().

我已经添加到帖子:异常,映射文件和项目文件结构。

I have added to the post: the exception, the mapping from the mapping file and the project file structure.

任何建议都很好。



<!-- Names the annotated entity class -->
<mapping resource="org/hibernate/tutorial/chapter1/domain/Event.hbm.xml"/>

推荐答案

确保您的Event.hbm.xml中有一个DOCTYPE HTML内容的顶部

Make sure you have a DOCTYPE in your Event.hbm.xml at the top of the XML content 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>

这篇关于Hibernate的映射问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 08:16
查看更多