当前位置:首页 > 开发 > 编程语言 > Hibernate > 正文

org.hibernate.MappingException: Association references unmapped class: com.lj.zh

发表于: 2013-11-15   作者:alleni123   来源:转载   浏览次数:
摘要: Caused by: org.hibernate.MappingException: Association references unmapped class: com.lj.zhang.Order at org.hibernate.cfg.HbmBinder.bindCollectionSecondPass(HbmBinder.java:2521) at org.hibernate.c
Caused by: org.hibernate.MappingException: Association references unmapped class: com.lj.zhang.Order
at org.hibernate.cfg.HbmBinder.bindCollectionSecondPass(HbmBinder.java:2521)
at org.hibernate.cfg.HbmBinder$CollectionSecondPass.secondPass(HbmBinder.java:2807)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:69)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1611)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1369)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1756)
at util.HibernateUtil.buildSessionFactory(HibernateUtil.java:19)
at util.HibernateUtil.<clinit>(HibernateUtil.java:13)
... 1 more



这个错误出现在
/**
	 * Called for all collections
	 */
	public static void bindCollectionSecondPass(Element node, Collection collection,
			java.util.Map persistentClasses, Mappings mappings, java.util.Map inheritedMetas)
			throws MappingException {

		if ( collection.isOneToMany() ) {
			OneToMany oneToMany = (OneToMany) collection.getElement();
			String assocClass = oneToMany.getReferencedEntityName();
			PersistentClass persistentClass = (PersistentClass) persistentClasses.get( assocClass );
			if ( persistentClass == null ) {
				throw new MappingException( "Association references unmapped class: " + assocClass );
			}
			oneToMany.setAssociatedClass( persistentClass );
			collection.setCollectionTable( persistentClass.getTable() );

			if ( LOG.isDebugEnabled() ) {
				LOG.debugf( "Mapping collection: %s -> %s", collection.getRole(), collection.getCollectionTable().getName() );
			}
		}


原因是我在User.hbm.xml中配置了One-to-many  , class是Order.

可是Order这个对象的hbm.xml我并没有在hibernate.cfg.xml中配置。
也就是缺少了<mapping resource="Order.hbm.xml"/>
导致出错。


看来Hibernate会在启动时对这些进行很仔细的检查,
怪不得启动这么慢。

org.hibernate.MappingException: Association references unmapped class: com.lj.zh

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
多次遇到这个错误,难以解决,有时候出现,有时候没有,很神奇,今天发现了一点端倪,虽然说不上找
【objc runtime之association】  1、objc runtime association函数有3个,功能是给某个instance添
Summary:两个类都需要使用对方特性,但其间只有一条单向连接。添加一个反向指针,并使修改函数能够
Summary:两个类之间有双向关联,但其中一个类如今不再需要另一个类的特性。去除不必要的关联。 动
References and foreach References in PHP are bad, as I mentioned before, and you certainly sh
转 贴: http://blog.csdn.net/booknut/archive/2009/03/11/3980936.aspx UML中对象的几种关系: as
1. Dependency: A dependency is a weak relationship between two classes. In this example, ther
1. Overview UML设计类中,类的关系分为Generalization(泛化),Dependency(依赖关系)、Association(
1. Overview UML设计类中,类的关系分为Generalization(泛化),Dependency(依赖关系)、Association(
UML中依赖泛化关联实现聚合组合的Java实现 UML中依赖泛化关联实现聚合组合的Java实现 在类图中,类
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号