本帖最后由 lihao1129 于 2009-09-01 16:32:47 编辑

解决方案 »

  1.   

    com.whhd.entity.ArticleId这个异常了,都没贴全,这句很重要啊
    TransientObjectException事物异常,是否有主外键关系之类
      

  2.   

    但是我做添加功能的时候蛮好捏...
    2009-9-1 15:43:00 org.apache.catalina.core.StandardWrapperValve invoke
    严重: Servlet.service() for servlet action threw exception
      

  3.   

    你的主键对象是暂态对象 因为它和外键对象都在同一个hibernate事务中 这个事务没有提交 你的主键对象就没有在数据库生成数据,那么你再用它的id插入外键表 当然是不行了~~ 可能是你的hibernate配置文件的主外键关联配置的不对细心检查一下
    在不行,一句句执行,看哪句错误
      

  4.   

    我这个还外键里 有问题,后来我就判断,如果在用ID查询出来的实体与ACTIONFORM里面不一致说明修改过了的,再到外键里修改,用“!=”但是,你看我前面的SYSO打印控制台语句,控制台上都是相等的 还会进入到IF里 好奇怪哈..我全部改成“==”至少不会报错,但是外键值不能修改,所以说 还是外键有问题
    public ActionForward doUpdate(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) {
    System.out.println("进入到doUpdate");
    HdmainForm hf = (HdmainForm) form; ArticleId art = new ArticleId();
    Corporation cor = new Corporation();
    Hddate hdd = new Hddate();
    Hdmain hd = hdmainBiz.findbyId(hf.getHdmain()); System.out.println("hd:" + hd.getArticleId().getArticleIdAta()
    + " hf:" + hf.getHdATA());
    System.out.println("hd:" + hd.getArticleId().getArticleIdName() + " hf:"
    + hf.getHdarticleId());
    if (hd.getArticleId().getArticleIdAta().trim() != hf.getHdATA().trim()
    || hd.getArticleId().getArticleIdName().trim() != hf.getHdarticleId().trim()) {
    // 如果这个外键没有改动的话
    System.out.println("进入DOUPDATE里的IF");
    art.setArticleIdName(hf.getHdarticleId());
    System.out.println(hf.getHdATA());
    art.setArticleIdAta(hf.getHdATA());
    articleIdBiz.updateIArticle(art);// 如果没有这个件号系统就会添加这个件号
    hd.setArticleId(art);// 然后在把这个件号给hd的外键给予联系
    }
    System.out.println("111111111");
    hd.setMainCycle(hf.getHdCycle());// 周期
    hd.setMainWarrantyTime(hf.getHdWarrantyTime());// 保修期
    hd.setMainManhourTest(hf.getHdmanhourTest());
    hd.setMainManhourRepair(hf.getHdmanhourRepair());
    hd.setMainManhourOverhaul(hf.getHdmanhourOverhaul());
    hd.setMainImmobilityRepair(hf.getHdimmobilityRepair());
    hd.setMainImmobilityOverhaul(hf.getHdimmobilityOverhaul()); System.out.println("日期类看看:" + hf.getHdDate());
    if (hd.getHddate().getDateData() != hf.getHdDate()) {
    hdd.setDateData(hf.getHdDate());
    hd.setHddate(hdd);
    hddateBiz.updateIArticle(hdd);
    } if (hd.getCorporation().getCorporationName() != hf.getHdCorporation()) {
    cor.setCorporationName(hf.getHdCorporation());// 添加公司名称
    corporationBiz.updateIArticle(cor);
    hd.setCorporation(cor);// 添加入外键的公司名称
    }
    System.out.println("看看是否能进判断语句");
    hdmainBiz.updateHdmain(hd);
    return mapping.findForward("update_success");
    }
      

  5.   


             art.setArticleIdName(hf.getHdarticleId());//先插入外键表的2个值
                art.setArticleIdAta(hf.getHdATA());
                articleIdBiz.updateIArticle(art);// 然后先更新外键表
                hd.setArticleId(art);//然后再把外键表的值传到主表里
    //这样应该是对的吧..
      

  6.   

    The given object has a null identifier: com.whhd.entity.ArticleId-----得到的对象是一个空的标示符这个主键可能配置有问题
      

  7.   

    com.whhd.entity.ArticleId的ID为空。
    看下你的主键生成策略,是不是自动生成主键的。如果要给主键赋值。
    articleIdBiz.updateIArticle(art);//如果没有这个件号系统就会添加这个件号
    在你更新art之前,art还是一个暂态对象,不可以直接更新。
    如果DAO中不是直接用update而是saveOrUpdate倒是可以(需要Hibernate为你生成主键).
      

  8.   

    主表main
    <?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.whhd.entity.Hdmain" table="hdmain" schema="dbo">
            <id name="mainId" type="java.lang.Integer">
                <column name="main_ID" />
                <generator class="native" />
            </id>
            <many-to-one name="articleId" class="com.whhd.entity.ArticleId" fetch="select" lazy="false">
                <column name="main_ArticleId" />
            </many-to-one>
            <many-to-one name="hddate" class="com.whhd.entity.Hddate" fetch="select" lazy="false">
                <column name="main_Date" />
            </many-to-one>
            <many-to-one name="corporation" class="com.whhd.entity.Corporation" fetch="select" lazy="false">
                <column name="main_Corporation" />
            </many-to-one>
            <property name="mainManhourTest" type="java.lang.String">
                <column name="main_manhour_Test" length="50" />
            </property>
            <property name="mainManhourRepair" type="java.lang.String">
                <column name="main_manhour_Repair" length="50" />
            </property>
            <property name="mainManhourOverhaul" type="java.lang.String">
                <column name="main_manhour_Overhaul" length="50" />
            </property>
            <property name="mainImmobilityRepair" type="java.lang.String">
                <column name="main_immobility_Repair" length="50" />
            </property>
            <property name="mainImmobilityOverhaul" type="java.lang.String">
                <column name="main_immobility_Overhaul" length="50" />
            </property>
            <property name="mainWarrantyTime" type="java.lang.String">
                <column name="main_WarrantyTime" length="50" />
            </property>
            <property name="mainCycle" type="java.lang.String">
                <column name="main_Cycle" length="50" />
            </property>
        </class>
    </hibernate-mapping>外键表Corporation 表
    <?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.whhd.entity.Corporation" table="corporation" schema="dbo">
            <id name="corporationId" type="java.lang.Integer">
                <column name="corporation_Id" />
                <generator class="native" />
            </id>
            <property name="corporationName" type="java.lang.String">
                <column name="corporation_Name" length="50" />
            </property>
            <set name="hdmains" inverse="true">
                <key>
                    <column name="main_Corporation" />
                </key>
                <one-to-many class="com.whhd.entity.Hdmain" />
            </set>
        </class>
    </hibernate-mapping>
    ArticleId外键表
    <?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.whhd.entity.ArticleId" table="articleId" schema="dbo">
            <id name="articleIdId" type="java.lang.Integer">
                <column name="articleId_Id" />
                <generator class="native" />
            </id>
            <property name="articleIdName" type="java.lang.String">
                <column name="articleId_Name" length="50" />
            </property>
            <property name="articleIdAta" type="java.lang.String">
                <column name="articleId_ATA" length="50" />
            </property>
            <set name="hdmains" inverse="true">
                <key>
                    <column name="main_ArticleId" />
                </key>
                <one-to-many class="com.whhd.entity.Hdmain" />
            </set>
        </class>
    </hibernate-mapping>
      

  9.   

    用回调就能解决了,hibernate的session关闭了.
      

  10.   

    hibernate的session关闭了,,你修改lazey(最好不要),或者在web里面配置 ,延时加载就行了;另外游离状态的数据貌似不能update吧
      

  11.   

    问题的关键就是 主键值为空、或不是合法值,而无法进行 数据update。
      

  12.   

    同样的错误,应该不是主键设置的问题。
    可能是"update” 修改数据的特殊性。
      

  13.   

    修改的时候,应该把主键传到action里面去。不然找不到啊