最近做一个java ee的项目。从别人那儿接手的。
他的model是myeclipse反向工程自动生成的。
结果出了这么个异常:
org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity不知道我的配置文件是不是哪儿出了问题?
请各位大虾帮忙看看~~。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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/sms</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</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>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/model/Users.hbm.xml</value>
<!-- 这里可以添加所有需要的POJ映射文件 -->
</list>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<!-- 事务拦截器bean需要依赖注入的一个事务管理器 -->
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<!-- 下面定义的是事物传播属性 -->
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="find*">PROPAGATION_SUPPORTS,readOnly</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="del*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!-- 定义BeanNameAutoProxyCreator来简化事务配置-->
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<!-- 定义所有需要自动创建事务代理的bean -->
<property name="beanNames">
<list>
<value>UserDAO</value>
<value>UserService</value>
</list>
<!-- 这里可以增加其他需要自动创建事务代理的bean -->
</property>
<!-- 定义 BeanNameAutoProxyCreator所需的事务拦截器-->
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
<!-- 这里可以增加其他新的Interceptor -->
</list>
</property>
</bean>
<bean id="userService" class="com.service.impl.UserServiceImpl">
<property name="userDao" ref="userDao"></property>
</bean>
<bean id="memoService" class="com.service.impl.MemoServiceImpl">
<property name="memoDao" ref="memoDao"></property>
</bean>
<bean id="userDao" class="com.dao.impl.UserDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="memoDao" class="com.dao.impl.MemoDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean name="login" class="com.action.LoginAction" scope="prototype" autowire="byName" />
<bean id="saveUserAction" class="com.action.SaveUserAction" scope="prototype">
<property name="service" ref="userService"></property>
</bean>
<bean name="listUserAction" class="com.action.ListUserAction" scope="prototype">
<property name="service" ref="userService"></property>
</bean>
<bean name="updatePUserAction" class="com.action.UpdatePUser" scope="prototype">
<property name="service" ref="userService"></property>
</bean>
<bean name="updateUserAction" class="com.action.UpdateUserAction" scope="prototype">
<property name="service" ref="userService"></property>
</bean>
<bean name="removeUserAction" class="com.action.RemoveUserAction" scope="prototype">
<property name="service" ref="userService"></property>
</bean>
<bean name="addMemoAction" class="com.action.AddMemoAction" scope="prototype" autowire="byType">
<property name="service" ref="memoService"></property>
</bean>
<bean name="deleteMemoAction" class="com.action.DeleteMemoAction" scope="prototype" autowire="byType">
<property name="service" ref="memoService"></property>
</bean>
<bean name="updateMemoAction" class="com.action.UpdateMemoAction" scope="prototype" autowire="byType">
<property name="service" ref="memoService"></property>
</bean>
<bean name="queryMemoAction" class="com.action.QueryMemoAction" scope="prototype" autowire="byType">
<property name="service" ref="memoService"></property>
</bean>
</beans>Memo.hbm.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.model.Memo" table="memo" catalog="sms">
<composite-id name="id" class="com.model.MemoId">
<key-property name="id" type="java.lang.Integer">
<column name="id" />
</key-property>
<key-property name="title" type="java.lang.String">
<column name="title" length="20" />
</key-property>
<key-property name="content" type="java.lang.String">
<column name="content" length="60" />
</key-property>
<key-property name="remindTime" type="java.lang.String">
<column name="remindTime" length="8" />
</key-property>
<key-property name="remindMode" type="java.lang.Integer">
<column name="remindMode" />
</key-property>
<key-property name="creator" type="java.lang.String">
<column name="creator" length="30" />
</key-property>
<key-property name="flag" type="java.lang.String">
<column name="flag" length="50" />
</key-property>
<key-property name="isRead" type="java.lang.Integer">
<column name="isRead" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>
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> <session-factory>
<mapping resource="./Users.hbm.xml" />
<mapping resource="model/Users.hbm.xml" />
<mapping resource="com/model/Memo.hbm.xml" />
</session-factory>
</hibernate-configuration>
麻烦各位大虾帮帮忙,看看到底是哪里出问题了纠结了很久了。也把save方法改成save("com.model.Memo",memo)了。还是不行。
一直出现 Unknow Entity
蛋疼啊。
他的model是myeclipse反向工程自动生成的。
结果出了这么个异常:
org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity不知道我的配置文件是不是哪儿出了问题?
请各位大虾帮忙看看~~。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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/sms</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</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>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/model/Users.hbm.xml</value>
<!-- 这里可以添加所有需要的POJ映射文件 -->
</list>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<!-- 事务拦截器bean需要依赖注入的一个事务管理器 -->
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<!-- 下面定义的是事物传播属性 -->
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="find*">PROPAGATION_SUPPORTS,readOnly</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="del*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!-- 定义BeanNameAutoProxyCreator来简化事务配置-->
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<!-- 定义所有需要自动创建事务代理的bean -->
<property name="beanNames">
<list>
<value>UserDAO</value>
<value>UserService</value>
</list>
<!-- 这里可以增加其他需要自动创建事务代理的bean -->
</property>
<!-- 定义 BeanNameAutoProxyCreator所需的事务拦截器-->
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
<!-- 这里可以增加其他新的Interceptor -->
</list>
</property>
</bean>
<bean id="userService" class="com.service.impl.UserServiceImpl">
<property name="userDao" ref="userDao"></property>
</bean>
<bean id="memoService" class="com.service.impl.MemoServiceImpl">
<property name="memoDao" ref="memoDao"></property>
</bean>
<bean id="userDao" class="com.dao.impl.UserDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="memoDao" class="com.dao.impl.MemoDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean name="login" class="com.action.LoginAction" scope="prototype" autowire="byName" />
<bean id="saveUserAction" class="com.action.SaveUserAction" scope="prototype">
<property name="service" ref="userService"></property>
</bean>
<bean name="listUserAction" class="com.action.ListUserAction" scope="prototype">
<property name="service" ref="userService"></property>
</bean>
<bean name="updatePUserAction" class="com.action.UpdatePUser" scope="prototype">
<property name="service" ref="userService"></property>
</bean>
<bean name="updateUserAction" class="com.action.UpdateUserAction" scope="prototype">
<property name="service" ref="userService"></property>
</bean>
<bean name="removeUserAction" class="com.action.RemoveUserAction" scope="prototype">
<property name="service" ref="userService"></property>
</bean>
<bean name="addMemoAction" class="com.action.AddMemoAction" scope="prototype" autowire="byType">
<property name="service" ref="memoService"></property>
</bean>
<bean name="deleteMemoAction" class="com.action.DeleteMemoAction" scope="prototype" autowire="byType">
<property name="service" ref="memoService"></property>
</bean>
<bean name="updateMemoAction" class="com.action.UpdateMemoAction" scope="prototype" autowire="byType">
<property name="service" ref="memoService"></property>
</bean>
<bean name="queryMemoAction" class="com.action.QueryMemoAction" scope="prototype" autowire="byType">
<property name="service" ref="memoService"></property>
</bean>
</beans>Memo.hbm.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.model.Memo" table="memo" catalog="sms">
<composite-id name="id" class="com.model.MemoId">
<key-property name="id" type="java.lang.Integer">
<column name="id" />
</key-property>
<key-property name="title" type="java.lang.String">
<column name="title" length="20" />
</key-property>
<key-property name="content" type="java.lang.String">
<column name="content" length="60" />
</key-property>
<key-property name="remindTime" type="java.lang.String">
<column name="remindTime" length="8" />
</key-property>
<key-property name="remindMode" type="java.lang.Integer">
<column name="remindMode" />
</key-property>
<key-property name="creator" type="java.lang.String">
<column name="creator" length="30" />
</key-property>
<key-property name="flag" type="java.lang.String">
<column name="flag" length="50" />
</key-property>
<key-property name="isRead" type="java.lang.Integer">
<column name="isRead" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>
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> <session-factory>
<mapping resource="./Users.hbm.xml" />
<mapping resource="model/Users.hbm.xml" />
<mapping resource="com/model/Memo.hbm.xml" />
</session-factory>
</hibernate-configuration>
麻烦各位大虾帮帮忙,看看到底是哪里出问题了纠结了很久了。也把save方法改成save("com.model.Memo",memo)了。还是不行。
一直出现 Unknow Entity
蛋疼啊。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货