`

Hibernate的org.hibernate.MappingException: Unknown entity:

阅读更多
许多初学者在学习Hibernate的时候,总会遇到这样的问题。org.hibernate.MappingException: Unknown entity: ******
今天我在调试程序的时候也遇到了此问题,最终终于解决,下面我的一些总结下。
一句话:“因为你的映射文件(*.hbm.xml) 没有被映射”
问题出现的原因,有几下几点:
1,检查你的映射文件的名字是否和你的pojo(*.java)的名字是否相同。
2.映射文件的名字是*.hbm.xml而不是*.xml
3.你是否加载了你的映射文件。
      加载的方法有两种
   (1)在你的Hibernate.cfg.xml配置文件中加载映射文件
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>
              …………
              …………
         <!-- 用于记载映射文件Student.hbm.xml-->
     <mapping resource="com/Students.hbm.xml"/>
     </session-factory>
</hibernate-configuration>
    (2)在你的测试代码的加载映射文件
           Configuration cfg = new Configuration();
           cfg.configure();
           cfg.addClass(*.class);    这里的*.class是你的映射文件的名字*.hbm.class中的*。。。
      但是你要注意,用第二种方法加载的时候,你的*.hbm.class文件必须位于classpath下面。
分享到:
评论

相关推荐

    Spring3.1 集成 JBPM4.4

    NULL 博文链接:https://guoyinjian.iteye.com/blog/1259538

    hibernate常见问题及处理.doc

    4. `org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save():` 此异常意味着在尝试保存对象前,对象的主键没有被正确设置。通常,这是由于在映射...

    hibernate常见异常

    本文将介绍 Hibernate 中的一些常见异常,包括 net.sf.hibernate.MappingException、net.sf.hibernate.PropertyNotFoundException、org.hibernate.id.IdentifierGenerationException 以及 a different object with ...

    hudson构建错误及解决方法

    Hudson持续集成工具可以集成Maven工具,并支持其项目的自动化构件,我们可以通过对其配置达到以Maven的形式将构件项目自动化管理起来的目的。

    org.dozer JAR 包(实现java bean mapper)

    dozer是一款优秀的java bean映射开源框架,完成深度转换Bean&lt;-&gt;Bean的Mapper实现

    EmbeddableTypes

    ( org.hibernate.MappingException: Repeated column in mapping for entity:YOUR_ENTITY ),因为表databsae不能具有重复的列名。 JPA定义了@AttributeOverride批注来处理此senario。 @AttributeOverrides({ @...

    hibernate核心,一对多,多对多映射讲解,看了就完全搞明白了

    `MappingException: Unknown entity` 异常通常意味着Hibernate无法识别或找不到指定的实体类。在本例中,问题在于Hibernate配置文件`Hibernate.cfg.xml`中没有包含`TblUser`实体的映射信息。要解决这个问题,你需要...

    Castor.docx

    import org.exolab.castor.mapping.MappingException; import org.exolab.castor.xml.MarshalException; import org.exolab.castor.xml.Marshaller; import org.exolab.castor.xml.Unmarshaller; import org.exolab....

Global site tag (gtag.js) - Google Analytics