Spring +hibernate 整合时,加入外键就出错 80
小弟初学SSH(看韩顺平老师讲座),遇到一个问题,卡了三天了,怎么调试都过不去,三天了,真让人感觉烦燥,特来求助,希望有能人之士能够为我解决一下,问题现象如下:两张表,E...
小弟初学SSH (看韩顺平老师讲座),遇到一个问题,卡了三天了,怎么调试都过不去,三天了,真让人感觉烦燥,特来求助,希望有能人之士能够为我解决一下,问题现象如下:
两张表,Employee(员工) Department(部门),在没有设置表外键关联的情况下,读写都一切正常。一但设置了表关联,也就是Employee.hbm.xml 文件中配有如下语句时,tomcat启动即报错:
<many-to-one name="department" class="com.yuqiang.domain.Department" fetch="join">
<column name="department_id" />
</many-to-one>
错误信息是:
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: An association from the table employee refers to an unmapped class: com.yuqiang.domain.Department
去掉<many-to-one>后就一切正常。
主要配置代码:
<!-- 配置会话工厂() -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 设置数据源 -->
<property name="dataSource" ref="dataSource"/>
<!-- 接管了hibernate对象映射文件 -->
<property name="mappingResources">
<list>
<value>com/yuqiang/domain/Employee.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.hbm2ddl.auto=update
hibernate.show_sql=true
</value>
</property>
</bean>
以下是错误截图
以下是配置文件 展开
两张表,Employee(员工) Department(部门),在没有设置表外键关联的情况下,读写都一切正常。一但设置了表关联,也就是Employee.hbm.xml 文件中配有如下语句时,tomcat启动即报错:
<many-to-one name="department" class="com.yuqiang.domain.Department" fetch="join">
<column name="department_id" />
</many-to-one>
错误信息是:
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: An association from the table employee refers to an unmapped class: com.yuqiang.domain.Department
去掉<many-to-one>后就一切正常。
主要配置代码:
<!-- 配置会话工厂() -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 设置数据源 -->
<property name="dataSource" ref="dataSource"/>
<!-- 接管了hibernate对象映射文件 -->
<property name="mappingResources">
<list>
<value>com/yuqiang/domain/Employee.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.hbm2ddl.auto=update
hibernate.show_sql=true
</value>
</property>
</bean>
以下是错误截图
以下是配置文件 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询