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

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

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

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

    雪山飛鵠

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

    BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
      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進(jìn)行save的時候檢測到beannull

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

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

    3)        DAO層代碼是否錯誤

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

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

    首先看Action中的代碼

    private Employee employee;

        public Employee getEmployee() {

            returnemployee;

        }

        publicvoid setEmployee(Employee employee) {

            this.employee = employee;

        }

    這里employee是我們觀察的重點(diǎn)

    再看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屬性的值

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

    <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>

    由此我們得出的結(jié)論是:

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

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

    Feedback

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

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

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

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

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

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

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

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

    # re: attempt to create saveOrUpdate event with null entity 2013-11-23 16:12 ilex
    因?yàn)閑mployee是一個對象@dgd
      回復(fù)  更多評論
      

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

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

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

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

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

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

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

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

    # 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",這個地方如果你賦值的時候給了一個空值 也會出這個異常  回復(fù)  更多評論
      

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

    主站蜘蛛池模板: 亚洲av永久无码精品秋霞电影秋| 131美女爱做免费毛片| 亚洲av极品无码专区在线观看| 亚洲美女在线国产| 蜜桃视频在线观看免费网址入口| 青柠影视在线观看免费高清| 99亚洲男女激情在线观看| 亚洲一卡二卡三卡四卡无卡麻豆| 国产成人精品日本亚洲网站| 亚洲精品tv久久久久| 国产免费人人看大香伊| 国产人成免费视频网站| 99精品在线免费观看| 黄色视屏在线免费播放| 美女扒开尿口给男人爽免费视频| 亚洲色大成网站www| 亚洲a级片在线观看| 亚洲精品中文字幕乱码| 久久精品7亚洲午夜a| 成人午夜亚洲精品无码网站| 亚洲第一福利网站在线观看| 国产精品四虎在线观看免费| 成全影视免费观看大全二| 99在线精品视频观看免费| 亚洲免费一级视频| 国产成人免费高清激情明星| 24小时免费看片| 99re6免费视频| 亚洲国产精品免费视频| 久久国产乱子伦精品免费看| 日本免费一区二区久久人人澡| 两个人看的www免费视频中文| 成人无码精品1区2区3区免费看| 国产精品九九久久免费视频 | 好湿好大好紧好爽免费视频| 一个人看的免费视频www在线高清动漫 | 黄色网址在线免费观看| 无码亚洲成a人在线观看| 亚洲欧美在线x视频| 免费播放国产性色生活片| 一区二区视频在线免费观看|