首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

在添加数据是出现:Unknown entity,该怎么解决

2012-05-09 
在添加数据是出现:Unknown entity整了老久了都没有发现是哪的问题:我是新手,麻烦高手指点一下下面是错误代

在添加数据是出现:Unknown entity
整了老久了都没有发现是哪的问题:我是新手,麻烦高手指点一下

下面是错误代码:
具体的代码如下:

Java code
org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: com.oa.model.Organization$$EnhancerByCGLIB$$40141085; nested exception is org.hibernate.MappingException: Unknown entity: com.oa.model.Organization$$EnhancerByCGLIB$$40141085    org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:676)    org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)    org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)    org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)    org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:694)    com.oa.dao.imp.OrgDaoImp.addOrg(OrgDaoImp.java:15)


Organization.hbm.xml

Java code
<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping>    <class name="com.oa.model.Organization" table="t_organization">        <id name="id">            <generator class="native"/>        </id>        <property name="name"/>        <property name="sn"/>        <property name="description"/>        <many-to-one name="parent" column="pid"></many-to-one>        <set name="children" >            <key column="pid"></key>            <one-to-many class="com.oa.model.Organization"/>        </set>    </class></hibernate-mapping>

action 代码:


Java code
package com.oa.web;import javax.annotation.Resource;import com.oa.model.Organization;import com.oa.service.OrgService;public class OrgAction {        @Resource OrgService orgService;        private Organization organization;        public Organization getOrganization() {            return organization;        }        public void setOrganization(Organization organization) {            this.organization = organization;        }        public void add()        {                    this.orgService.addOrg(this.organization,0);        }}


application代码:

Java code
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"        destroy-method="close">        <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />        <property name="url"            value="jdbc:sqlserver://localhost:1433;DataBaseName=moa" />        <property name="username" value="sa" />        <property name="password" value="yczn" />        <!-- 连接池启动时的初始值 -->        <property name="initialSize" value="1" />        <!-- 连接池的最大值 -->        <property name="maxActive" value="500" />        <!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 -->        <property name="maxIdle" value="2" />        <!--  最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 -->        <property name="minIdle" value="1" />    </bean>    <bean id="sessionFactory"        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">        <property name="dataSource" ref="dataSource" />        <property name="mappingDirectoryLocations">            <list>                 <value>classpath:/com/oa/vo</value>            </list>        </property>                <property name="hibernateProperties">            <value>                hibernate.dialect=org.hibernate.dialect.SQLServerDialect                hibernate.hbm2ddl.auto=updata                hibernate.show_sql=true                hibernate.format_sql=true            </value>        </property>    </bean><bean id="orgService" class="com.oa.service.imp.OrgServicImp" >    </bean>    <bean id="orgAction" class="com.oa.web.OrgAction">    </bean> 



现在是能得到页面的数据,但是添加时出现上述错误,望高手解答:
还有就是,如果是new一个实体类进行添加时,是没有问题的....

[解决办法]
Java code
package com.oa.web;import javax.annotation.Resource;import com.oa.model.Organization;import com.oa.service.OrgService;public class OrgAction {        @Resource OrgService orgService;        private Organization organization;        public Organization getOrganization() {            return organization;        }        public void setOrganization(Organization organization) {            this.organization = organization;        }        public void add()        {                    this.orgService.addOrg(this.organization,0);        }} 

热点排行