<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    溫馨提示:您的每一次轉載,體現了我寫此文的意義!!!煩請您在轉載時注明出處http://www.tkk7.com/sxyx2008/謝謝合作!!!

    雪山飛鵠

    溫馨提示:您的每一次轉載,體現了我寫此文的意義!!!煩請您在轉載時注明出處http://www.tkk7.com/sxyx2008/謝謝合作!!!

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      215 Posts :: 1 Stories :: 674 Comments :: 0 Trackbacks
     

    今天在寫struts2 save的時候報了這么一個異常

    java.lang.IllegalArgumentException: attempt to create saveOrUpdate event with null entity

        at org.hibernate.event.SaveOrUpdateEvent.<init>(SaveOrUpdateEvent.java:40)

        at org.hibernate.event.SaveOrUpdateEvent.<init>(SaveOrUpdateEvent.java:23)

        at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518)

        at org.hibernate.impl.SessionImpl.save(SessionImpl.java:514)

    從上面的異常信息可以看出是在Hibernate進行save的時候檢測到beannull

    1)        大致從這幾個方面來分析原因:

    2)        Hibernate(*.hbm.xml)映射文件是否錯誤

    3)        DAO層代碼是否錯誤

    4)        檢查Action及視圖層jsp頁面等

    從上面幾個逐個檢查后得出的結論為第四條

    首先看Action中的代碼

    private Employee employee;

        public Employee getEmployee() {

            returnemployee;

        }

        publicvoid setEmployee(Employee employee) {

            this.employee = employee;

        }

    這里employee是我們觀察的重點

    再看jsp中的代碼

    <s:form action="saveEmployee.action">

            <s:textfield name="empName" label="empName"></s:textfield>

            <s:textfield name="age" label="age"></s:textfield>

            <s:textfield name="sex" label="sex"></s:textfield>

            <s:textfield name="context" label="context"></s:textfield>

            <s:submit value="注冊" theme="simple"></s:submit>

            <s:reset value="取消" theme="simple"></s:reset>

    </s:form>

    大家注意<s:textfield/>name屬性的值

    很顯然錯誤發生在此處修改如下即可:

    <s:form action="saveEmployee.action">

            <s:textfield name="employee.empName" label="empName"></s:textfield>

            <s:textfield name="employee.age" label="age"></s:textfield>

            <s:textfield name="employee.sex" label="sex"></s:textfield>

            <s:textfield name="employee.context" label="context" value=""></s:textfield>

            <s:submit value="注冊" theme="simple"></s:submit>

            <s:reset value="取消" theme="simple"></s:reset>

        </s:form>

    由此我們得出的結論是:

    jsp頁面中一定要保持頁面中各個控件的name屬性與Action中模型驅動對象的名字一致否則就會報錯

    posted on 2009-10-19 11:39 雪山飛鵠 閱讀(27972) 評論(19)  編輯  收藏 所屬分類: Hibernate

    Feedback

    # re: attempt to create saveOrUpdate event with null entity 2010-11-07 16:18 smallmoon
    大哥,你幫了我一個大忙啊,真是,我也是遇到了這個問題。拜讀了你的文章之后,豁然開朗,謝謝哈  回復  更多評論
      

    # re: attempt to create saveOrUpdate event with null entity 2011-02-25 16:10 全球
    我已經這樣寫了 可還是這個錯誤啊  回復  更多評論
      

    # re: attempt to create saveOrUpdate event with null entity 2012-03-15 15:28 someone
    很給力!!!謝謝!!  回復  更多評論
      

    # re: attempt to create saveOrUpdate event with null entity 2012-04-03 22:30 二萬人
    解決了我的問題,謝謝  回復  更多評論
      

    # re: attempt to create saveOrUpdate event with null entity 2012-05-16 16:03 dgd
    怎么回事啊,我有兩個頁面添加,都是用的模型驅動啊,有一個加入了數據,還有一個報這個錯,不能加入數據,怎么有的解決的了,有的解決不了呢。知道底層是怎么實現的嗎。  回復  更多評論
      

    # re: attempt to create saveOrUpdate event with null entity 2012-05-16 16:21 dgd
    這樣還真解決了,謝謝。可是我還是不太清楚。我第一個頁面的時候,也是這樣寫的啊,也是用的模型驅動。是可以把數據加入進去的。第二個頁面加入數據的時候就不行了。用了你上面的方法才解決的。真不知道是為什么?要是可以看底層代碼的話。應該就可以找出是哪里出問題了。  回復  更多評論
      

    # 過客[未登錄] 2012-09-07 16:56 1
    真的很感謝你,問題解決了……  回復  更多評論
      

    # 真給力的工具[未登錄] 2013-03-26 17:28
    真的很給力,特別在spring中使用。。  回復  更多評論
      

    # re: attempt to create saveOrUpdate event with null entity 2013-11-23 16:12 ilex
    因為employee是一個對象@dgd
      回復  更多評論
      

    # re: attempt to create saveOrUpdate event with null entity[未登錄] 2013-11-23 16:15 candy
    愛死你了!!!  回復  更多評論
      

    # re: attempt to create saveOrUpdate event with null entity 2014-02-20 18:13 sdfwewerw
    我也遇到了,也是忘了加"對象."。  回復  更多評論
      

    # re: attempt to create saveOrUpdate event with null entity[未登錄] 2014-04-03 09:25 w
    有用,非常感謝。  回復  更多評論
      

    # re: attempt to create saveOrUpdate event with null entity 2014-04-27 20:31 多大的
    你這個問題解決了嗎,我跟你一樣啊@全球
      回復  更多評論
      

    # re: attempt to create saveOrUpdate event with null entity 2014-09-25 10:38 chenbin
    謝謝啦啦啦啦。  回復  更多評論
      

    # re: attempt to create saveOrUpdate event with null entity 2015-01-24 16:40 pei
    一樣的,但是沒解決問題  回復  更多評論
      

    # re: attempt to create saveOrUpdate event with null entity[未登錄] 2015-04-18 20:55 張云
    大哥。你的文章拯救了我啊。我這幾天在做畢業論文,打了一個Spring+hibernate+Strus2框架,可是一測試怎么出現此問題,找了幾天了找不出,郁悶死了。多虧看見你的文章了,總之,謝謝了。呵呵  回復  更多評論
      

    # re: attempt to create saveOrUpdate event with null entity[未登錄] 2016-02-24 10:45 shi
    沒有解決問題  回復  更多評論
      

    # re: attempt to create saveOrUpdate event with null entity[未登錄] 2016-03-08 15:11 影子
    @全球
    <property name="price" type="java.lang.Double">
    <column name="price" not-null="true">
    注意not_null="true",這個地方如果你賦值的時候給了一個空值 也會出這個異常  回復  更多評論
      

    # re: attempt to create saveOrUpdate event with null entity 2016-05-29 18:38 余糖糖
    沒有用,配置文件什么都是好的,寫一個測試類添加數據就可以,但是一到jsp頁面里面就不可以  回復  更多評論
      

    主站蜘蛛池模板: 国产成人精品日本亚洲| 又黄又大又爽免费视频| 亚洲处破女AV日韩精品| XXX2高清在线观看免费视频| www国产亚洲精品久久久| 特级毛片全部免费播放| 亚洲第一成人影院| 一级毛片免费观看不收费| 久久亚洲中文字幕精品一区| 两个人www免费高清视频| 亚洲av成人无码久久精品 | 91亚洲国产成人久久精品网站 | 亚洲天堂男人影院| 成年人视频在线观看免费| 亚洲乱码中文字幕在线| 亚洲国产成人久久笫一页| 十八禁视频在线观看免费无码无遮挡骂过| 亚洲自偷自偷在线制服| 久久免费的精品国产V∧| 亚洲一区二区三区在线观看蜜桃| 麻豆国产人免费人成免费视频| 美女的胸又黄又www网站免费| 永久亚洲成a人片777777| 91精品国产免费| 亚洲国产综合AV在线观看| 亚洲综合色成在线播放| 18以下岁毛片在免费播放| 亚洲伊人久久大香线蕉AV| 亚洲午夜精品第一区二区8050| 暖暖免费在线中文日本| 亚洲午夜无码久久| 国产成人综合亚洲亚洲国产第一页 | 亚洲中文字幕人成乱码| 哒哒哒免费视频观看在线www| 少妇性饥渴无码A区免费| 波多野结衣亚洲一级| 亚洲Av无码乱码在线观看性色| 久久久久久久岛国免费播放| 中文字幕精品三区无码亚洲| 久久久久无码专区亚洲av| 在线看免费观看AV深夜影院 |