【发布时间】:2016-07-02 02:17:59
【问题描述】:
我有 2 个课程:User 和 Branch。许多用户可以有一个分支。
IE。这是多对一的关联。
我的users 表位于第一个数据库中,名为fi,第二个数据库中的branch 表名为fi-master。
我正面临这个错误:
Caused by: org.hibernate.MappingException: An association from the table user refers to an unmapped class: com.hcl.fi.web.model.Branch
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1134)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1052)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:997)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:720)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
... 100 more
如何映射它们?
在userhbm:
<many-to-one name="branchDetail" column="branch_id" class="com.hcl.fi.web.model.Branch" cascade="all"
not-found="ignore" not-null="true"/>
【问题讨论】:
-
您可能忘记在
Branch类中添加@Entity。根据您的配置,您可能还需要在persistence.xml中声明Branch。 -
@ArnaudDenoyelle 他使用
xml映射。 -
请添加有关 Hibernate 版本以及所有 xml 映射和配置代码的信息。
标签: java mysql hibernate hibernate-mapping