许多初学者在学习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下面。
分享到:
相关推荐
NULL 博文链接:https://guoyinjian.iteye.com/blog/1259538
4. `org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save():` 此异常意味着在尝试保存对象前,对象的主键没有被正确设置。通常,这是由于在映射...
本文将介绍 Hibernate 中的一些常见异常,包括 net.sf.hibernate.MappingException、net.sf.hibernate.PropertyNotFoundException、org.hibernate.id.IdentifierGenerationException 以及 a different object with ...
Hudson持续集成工具可以集成Maven工具,并支持其项目的自动化构件,我们可以通过对其配置达到以Maven的形式将构件项目自动化管理起来的目的。
dozer是一款优秀的java bean映射开源框架,完成深度转换Bean<->Bean的Mapper实现
( org.hibernate.MappingException: Repeated column in mapping for entity:YOUR_ENTITY ),因为表databsae不能具有重复的列名。 JPA定义了@AttributeOverride批注来处理此senario。 @AttributeOverrides({ @...
`MappingException: Unknown entity` 异常通常意味着Hibernate无法识别或找不到指定的实体类。在本例中,问题在于Hibernate配置文件`Hibernate.cfg.xml`中没有包含`TblUser`实体的映射信息。要解决这个问题,你需要...
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....