日期:2014-05-17  浏览次数:20681 次

ssh项目hibernate 错误:org.hibernate.MappingException: Association references unmapped class: Message
我打算做一个音乐站点,Message 类是存放用户留言, User类存用户信息, 数据库现在建了2涨表,Message和User的关系是 多对一,也就是一个用户可以有多条留言,但是好像在做PO和数据库映射的时候出现了,问题,大家帮我看看,谢谢。
Message.hbm.xml: <hibernate-mapping package="edu.jlu.fuliang.domain">
<class name="Message" table="message" schema="music">
<id name="id" type="java.lang.Long">
<column name="MESSAGE_ID"/>
<generator class="identity"/>
</id>
<property name="messagecontent" type="java.lang.String">
<column name="MESSAGE_CONTENT" not-null="true"/>
</property>
<property name="messagedate" type="java.lang.String">
<column name="MESSAGE_DATE" not-null="true"/>
</property>
<many-to-one name="user" class="User" column="USER_ID" lazy="false"/>
</class>
</hibernate-mapping>

User.hbm.xml:<hibernate-mapping>
<class name="edu.jlu.fuliang.domain.User" table="USER">
<id name="id" type="java.lang.Long">
<column name="USER_ID"/>
<generator class="identity"/>
</id>
<property name="userName" type="java.lang.String">
<column name="USER_NAME" not-null="true"></column>
</property>
<property name="password" type="java.lang.String">
<column name="PASSWORD" not-null="true"/>
</property>
<set name="messages" table="message" inverse="true" cascade="save-update">
<key column="USER_ID"/>
<one-to-many class="Message"/> 
</set>

</class>
</hibernate-mapping>

applicationContext.xml:<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost/music">
</property>
<property name="username" value="root"></property>
<property name="password" value="123"></property>
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="show_sql">true</prop>
  <prop key="hibernate.hbm2ddl.auto">update</prop>
  <prop key="hibernate.jdbc.batch_size">20</prop>&n