org.hibernate.MappingException: Unknown entity

来源:互联网 发布:刘涛网络直播视频 编辑:程序博客网 时间:2024/06/05 21:09

最近学习Hiberante Annotations时遇到了该问题org.hibernate.MappingException: Unknown entity

原因一:

没有在*.cfg.xml文件中加入 *.hbm.xml造成的!!!

原因二:

映射文件的路径描述错误导致

<hibernate-configuration>
    <session-factory>

<mapping resource="com/atguigu/hibernate/entities/n21/both/Customer.hbm.xml"/>

    </session-factory>
</hibernate-configuration>

原因三:

这个我是引用的别的坛友的,自己暂时没遇到!!

发现是import Entity类造成的(使用Eclipse自动提示导入的该包)

import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.annotations.Entity;//这是就出问题了哦

@Entity
@Table(name
="test_person")
public class Person implements Serializable

后面修改了引入的Entity

import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Entity;//引入这个类就正确了

@Entity
@Table(name
="test_person")
public class Person implements Serializable


0 0
原创粉丝点击