把hbm和做更新的代码发上来看看啊

解决方案 »

  1.   

    http://www.blogjava.net/hrcdg/articles/157724.html
      

  2.   

    User.hbm.xml<?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.digitalcn.entity.UmsUser" table="UMS_USER" schema="HOSP_DBA">
            <id name="adminId" type="long">
                <column name="ADMIN_ID" precision="22" scale="0" />
                <generator class="native"> 
                  <param name="sequence">ums_user_adminId</param> 
                 </generator>         </id>
            <many-to-one name="eduObject" class="com.digitalcn.entity.EduObject" fetch="select">
                <column name="OBJECT_ID" precision="22" scale="0" />
            </many-to-one>
            <many-to-one name="umsGroup" class="com.digitalcn.entity.UmsGroup" fetch="select">
                <column name="ID" precision="22" scale="0" />
            </many-to-one>
            <property name="account" type="string">
                <column name="ACCOUNT" length="31" />
            </property>
            <property name="password" type="string">
                <column name="PASSWORD" length="63" />
            </property>
            <property name="status" type="long">
                <column name="STATUS" precision="22" scale="0" />
            </property>
            <property name="techType" type="long">
                <column name="TECH_TYPE" precision="22" scale="0" />
            </property>
            <property name="type" type="long">
                <column name="TYPE" precision="22" scale="0" />
            </property>
            <property name="lastLoginTime" type="timestamp">
                <column name="LAST_LOGIN_TIME" length="7" />
            </property>
            <property name="loginTimes" type="long">
                <column name="LOGIN_TIMES" precision="22" scale="0" />
            </property>
            <property name="idClass" type="long">
                <column name="ID_CLASS" precision="22" scale="0" />
            </property>
            <property name="identificationNo" type="string">
                <column name="IDENTIFICATION_NO" length="60" />
            </property>
            <property name="trueName" type="string">
                <column name="TRUE_NAME" length="60" />
            </property>
            <property name="gender" type="long">
                <column name="GENDER" precision="22" scale="0" />
            </property>
            <property name="telephone" type="string">
                <column name="TELEPHONE" length="20" />
            </property>
            <property name="phoneex" type="string">
                <column name="PHONEEX" length="10" />
            </property>
            <property name="fax" type="string">
                <column name="FAX" length="20" />
            </property>
            <property name="postcode" type="string">
                <column name="POSTCODE" length="10" />
            </property>
            <property name="email" type="string">
                <column name="EMAIL" />
            </property>
            <property name="address" type="string">
                <column name="ADDRESS" length="90" />
            </property>
            <property name="mobile" type="string">
                <column name="MOBILE" length="20" />
            </property>
            <property name="createTime" type="timestamp">
                <column name="CREATE_TIME" length="7" />
            </property>
            <property name="msnNum" type="string">
                <column name="MSN_NUM" />
            </property>
            <property name="qqNum" type="string">
                <column name="QQ_NUM" length="20" />
            </property>
            <property name="balance" type="long">
                <column name="BALANCE" precision="8" scale="0" />
            </property>
            <property name="principalship" type="string">
                <column name="PRINCIPALSHIP" length="30" />
            </property>
            <property name="creator" type="string">
                <column name="CREATOR" length="30" />
            </property>
            <property name="introduce" type="string">
                <column name="INTRODUCE" />
            </property>
            <property name="re" type="string">
                <column name="REMARK" />
            </property>
            <set name="umsUserRoles" 
                 table="UMS_USER_ROLE" 
                 >
                <key>
                    <column name="ADMIN_ID"/>
                </key>
               <many-to-many 
                class="com.digitalcn.entity.UmsRole" >
                 <column name="ID" not-null="true"/>
               </many-to-many>
                
                
                
            </set>
            
            <one-to-one name="umsUserinfo" class="com.digitalcn.entity.UmsUserinfo" cascade="all" outer-join="true"/>
            
            <set name="eduOrders" inverse="true">
                <key>
                    <column name="ADMIN_ID" precision="22" scale="0" />
                </key>
                <one-to-many class="com.digitalcn.entity.EduOrder" />
            </set>
            <!--
              <set name="umsGroup" inverse="true">
                <key>
                    <column name="ADMIN_ID" precision="22" scale="0" not-null="true" unique="true" />
                </key>
                <one-to-many class="com.digitalcn.entity.UmsGroup" />
            </set>
            -->
        </class>
    </hibernate-mapping>
      

  3.   

    Userinfo.hbm.xml<?xml version="1.0"?>
    <!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 - Hibernate Tools
    -->
    <hibernate-mapping>
        <class name="com.digitalcn.entity.UmsUserinfo" table="UMS_USERINFO" schema="HOSP_DBA">
            <id name="adminId" type="long">
                <column name="ADMIN_ID" precision="22" scale="0" />
                 <generator class="foreign"> 
                  <param name="property">umsUser</param> 
                 </generator> 
            </id>
              <one-to-one name="umsUser" class="com.digitalcn.entity.UmsUser" cascade="all" constrained="true"/>
            
            
            
            <property name="type" type="long">
                <column name="TYPE" precision="22" scale="0" />
            </property>
            <property name="status2" type="long">
                <column name="STATUS2" precision="22" scale="0" />
            </property>
            <property name="createTime" type="timestamp">
                <column name="CREATE_TIME" length="7" />
            </property>
            <property name="adminDesc" type="string">
                <column name="ADMIN_DESC" />
            </property>
            <property name="re" type="string">
                <column name="REMARK" />
            </property>
        </class>
    </hibernate-mapping>
      

  4.   

    更新的时候还是掉的SAVE()
    我也试了掉SAVEORUPDATE()
    还是报同样的错误!
    更新的时候我把原来的查出来然后在从新复值
    UserInfo表里的主建指定和不指定都包同样的错误!
      

  5.   

    你是不是new了一个新的PO类?然后把查出来的数据赋值进去,再saveOrUpdate()的?
      

  6.   

    你的<id>标签少了个属性
    <id unsaved-value="0" />
    然后用saveOrUpdate();试看看
      

  7.   

    更新相关的java代码贴出来看看
      

  8.   

     public void saveUmsUserinfo(UmsUser user){
       UmsUser ums=(UmsUser)this.getHibernateTemplate().load(UmsUser.class,new Long(user.getAdminId()));
       if(ums.getType()==2)
       {
       Hibernate.initialize(ums.getUmsUserinfo());
       }
     
       this.getHibernateTemplate().saveOrUpdate(user);
      

  9.   

    Hibernate.initialize(ums.getUmsUserinfo()); 
    这个方法看一下
      

  10.   

    这个是org.hibernate.hibernate包里自带的
    用于延时加载的!
      

  11.   

    我觉得原因就是延时加载的缘故,之前load出来的是个代理,然后没有去加载,你更新进去的时候可能就认为是一样的两个类了
    至少a different object with he same identifier value was already associated with the session 就是这个意思,你可以试一下不要去用延时加载看看
      

  12.   

    这个是从库里那出来的UserInfo里的信息
      

  13.   

    UmsUser   ums=(UmsUser)this.getHibernateTemplate().load(UmsUser.class,new   Long(user.getAdminId()));
          if(ums.getType()==2)
          {
          Hibernate.initialize(ums.getUmsUserinfo());
          } 
    感觉原因是:第1行让ums和session关联了,那么它的 umsUserinfo 属性也已经和session关联了。
    Hibernate.initialize(ums.getUmsUserinfo());这个也是让umsUserinfo 属性和session关联。
    才会报这样的错误。
      

  14.   

    只写UmsUser       ums=(UmsUser)this.getHibernateTemplate().load(UmsUser.class,new       Long(user.getAdminId()));
    也照样报上边的异常
      

  15.   

    这个问题经常出现在一对多映射和多对多映射中.解决方法有:把数据库中表之间的关联去掉,只需要进行session.clean()操作就可以解决了,有可能会报出"Found two representations of same collection", 然后session.refresh(object)最好的解决的方案是使用Hibernate里面自带的merge()方法。