軟件藝術思考者  
          混沌,彷徨,立志,蓄勢...
          公告
          日歷
          <2006年9月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          1234567

          導航

          隨筆分類(86)

          隨筆檔案(85)

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

           
          最近花了一個多月的時間,完成了一個微不足道的小東西,之所以花了這么長的時間,主要是對hibernate的運用不是很熟練。以至于出現(xiàn)了各種各式各樣的異常。
          1。其中時間最長的異常是無錯誤信息的異常。表現(xiàn)是數(shù)據(jù)庫死鎖。有經(jīng)驗的人當然能猜得到這是事務處理不當造成的,但由于沒有經(jīng)驗,
          我花費了一個星期的時間才改正。
          2。最奇怪的一個異常是:hibernate樂觀鎖異常。.hibernate3.HibernateOptimisticLockingFailureException: Unexpected row count: 2 expected: 1
          我用的是hibernate3,對數(shù)據(jù)庫數(shù)據(jù)的更新是默認的樂觀鎖。因為它是生來就相當樂觀的,不考慮我們這種新手常犯的錯誤,數(shù)據(jù)關聯(lián)重復。
          比如:從數(shù)據(jù)庫里取出一個對象,然后給它重新賦值,然后Update,如果其他表和它相關,而且有重復的記錄,就會報這樣的錯。解決方法是想辦法不讓其他表的相關數(shù)據(jù)記錄重復就可以解決。
          3。我遇到的另一個不常見的異常:UncategorizedSQLException錯誤原因,mssql中的text型字段為空值,將他加上默認值后恢復正常,具體原因不太清楚。
          org.springframework.jdbc.UncategorizedSQLException
          posted on 2006-09-15 14:41 智者無疆 閱讀(4900) 評論(7)  編輯  收藏 所屬分類: about hibernate
          評論:
          • # re: 關于hibernate的樂觀鎖異常  zhuzhu Posted @ 2006-09-15 14:59
            真是很復雜啊,你能自己解決這個bug我真的很佩服,除了崇拜就是佩服啦。嘿嘿。加油哦  回復  更多評論   

          • # re: 關于hibernate的樂觀鎖異常  xiaobai Posted @ 2006-09-15 15:05
            javascript全選功能
            1. <script language="javascript">
            <!--
            function check_all(form){
            arr = document.getElementsByName('box');
            for(i=0;i<arr.length;i++){
            arr[i].checked = true;
            }
            }

            -->
            </script>
            2. <INPUT type="checkbox" name="box" value="<%=news.getId()%>">
            3.
            <input type="button" value ='全選 'onclick="check_all(this)"/>
            <INPUT type="submit" value="刪除所選" onclick="return window.confirm('您確定這樣刪除嗎?')">
            4.action里的方法:
            String []str_ids=request.getParameterValues("box");
            if(str_ids!=null&&!str_ids.equals("")&&!str_ids.equals("null")){

            for(int i=0;i<str_ids.length;i++){
            if(!str_ids[i].equals("")&&!str_ids[i].equals("null")){
            Integer id =new Integer(str_ids[i]);
            getNewsDAO().deleteById(id);}
            return list(mapping,form,request,response);
            5
            public ActionForward list(
            ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response) {
            request.setAttribute("users",getNewsDAO().findAllNews());
            return mapping.findForward("newslist");
            }  回復  更多評論   

          • # re: 關于hibernate的樂觀鎖異常  壞男孩 Posted @ 2006-09-15 15:25
            我也遇到過,是在刪除數(shù)據(jù)的時候,不過不是每次都出這樣的錯誤,有的時候hibernate的錯誤怪怪的,不過畢竟hibernate還是最好的  回復  更多評論   

          • # re: 關于hibernate的樂觀鎖異常  智者無 Posted @ 2006-09-18 16:57
            //----使用jtds驅(qū)動吧--------------------
            <beans>

            <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName">
            <value>net.sourceforge.jtds.jdbc.Driver</value>
            </property>
            <property name="url">
            <value>jdbc:jtds:sqlserver://localhost:1433</value>
            </property>
            <property name="username">
            <value>sa</value>
            </property>
            </bean>
            <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="dataSource">
            <ref bean="dataSource" />
            </property>
            <property name="hibernateProperties">
            <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            </props>
            </property>  回復  更多評論   

          • # re: 關于hibernate的樂觀鎖異常  智者無 Posted @ 2006-09-18 16:58
            @智者無
            在郵箱里有驅(qū)動包  回復  更多評論   

          • # re: 關于hibernate的樂觀鎖異常  智者無 Posted @ 2006-09-19 11:37
            DWR中DWRUtil學習



            這些功能函數(shù)在下面這個網(wǎng)址都有示例,這里只是把他們用中文解釋,方便查找.
            http://getahead.ltd.uk/dwr/browser/util

            DWRUtil.getText(id)

            這個函數(shù)只能用于select

            getText(id) is similar to getValue(id), except that it is designed for <select ... lists where you need to get the displayed text rather than the value of the current option.

            這個函數(shù)主要的作用是取到當前select的顯示值即<option value>xxx</option>中xxx的內(nèi)容


            DWRUtil.getValue(id) 用來得到<option value>xxx</option>等元素的value值

            DWRUtil.getValue(id) is the read version of setValue(). This gets the values out of the HTML elements without you needing to worry about how a selection list differs from a div.



            這個函數(shù)能用于多個元素input type =textarea,text,Form button,formbutton,password(明文),
            Fancy button等元素,主要可以屏蔽原來對select元素getValue操作帶來的不便


            DWRUtil.getValues()


            getValues() is similar to getValue() except that the input is a Javascript object that contains name/value pairs. The names are assumed to be the IDs of HTML elements, and the values are altered to reflect the contents of those IDs. This method does not return the object in question, it alters the value that you pass to it.
            此函數(shù)主要是一次完成多個元素的getValue()操作,并將value的結果以js對象的形式封裝起來返回,參數(shù)是一個js對象,其中包含了希望取到value的element id
            e.g
            { div:null, textarea:null, select:null, text:null, password:null, formbutton:null, button:null}
            詳細參考http://getahead.ltd.uk/dwr/browser/util/getvalues查看效果
            DWRUtil.onReturn
            When inputs are part of a form then the return key causes the form to be submitted. When you are using Ajax, this is generally not what you want. Usually it would be far better if some JavaScript was triggered.Unfortunately different browsers handle events in quite a different manner. So DWRUtil.onReturn patches over the differences.
            在一個form表單中敲回車鍵將導致表單被遞交,這往往不是我們希望看到的.但是很多瀏覽器對這個事件的處理是不統(tǒng)一的,這個函數(shù)就是為了消除這個不統(tǒng)一的

            DWRUtil.onReturn(event, submitFunction)


            DWRUtil.selectRange
            Selecting a range of text in an input box
            You need to select text in an input box for any "Google suggest" type functions, however the selection model changes a lot between different browsers. The DWRUtil function to help here is: DWRUtil.selectRange(ele, start, end).
            在一個input元素中選擇一個范圍的字符串,可以查看
            http://getahead.ltd.uk/dwr/browser/util/selectrange操作

            DWRUtil.setValue(id, value)

            DWRUtil.setValue(id, value) finds the element with the id specified in the first parameter and alters its contents to be the value in the second parameter.
            This method works for almost all HTML elements including selects (where the option with a matching value and not text is selected), input elements (including textareas) divs and spans.
            主要是為了設值,屏蔽了select元素設值的問題,對select也可以方便的setvalue

            DWRUtil.setValues()
            Similar to setValue except that the input is a Javascript object that contains name/value pairs. The names are assumed to be the IDs of HTML elements, and the values, what we should set the contents of the elements.
            與getValues對應,傳入js對象,將對象中的value傳給相應的element

            DWRUtil.toDescriptiveString(id,degree)
            DWRUtil.toDescriptiveString is a better version of the toString() than the default. This function has a third parameter that declares the initial indent. This function should not be used from the outside world as it may well change in the future.
            此函數(shù)主要用來調(diào)試,傳入元素的id,調(diào)試的degree將顯示DOM信息
            此函數(shù)有第三個參數(shù),用于聲明初始化,包含第三個參數(shù)的調(diào)用不應該為使用,因為這個函數(shù)將來會改變
            DWRUtil.useLoadingMessage
            You must call this method after the page has loaded (i.e. not before the onload() event has fired) because it creates a hidden div to contain the loading message.
            你必須在頁面加載完成后(body onload事件)調(diào)用這個函數(shù),因為它會創(chuàng)建一個div,來包含一些消息.類似gmail的message模式的東西.為了達到在頁面加載完成后來操作,
            http://getahead.ltd.uk/dwr/browser/util/useloadingmessage
            提供了一些方法.例如
            <script>function init() { DWRUtil.useLoadingMessage();}if (window.addEventListener) { window.addEventListener("load", init, false);}else if (window.attachEvent) { window.attachEvent("onload", init);}else { window.onload = init;}</script>
            該參考頁面給出了2個類似的文字圖片實現(xiàn).
            DWRUtil.addOptions() 用返回的集合來填充select元素
            多種實現(xiàn),詳細參考http://getahead.ltd.uk/dwr/browser/lists

            DWRUtil.addRows() 返回的集合來填充table元素,或者tbody更為合適


              回復  更多評論   

          • # re: 關于hibernate的樂觀鎖異常  flash8627 Posted @ 2009-05-26 10:15
            還是沒有看到你的hibernate的樂觀鎖異常的解決方法  回復  更多評論   

           
          Copyright © 智者無疆 Powered by: 博客園 模板提供:滬江博客


             觀音菩薩贊

          主站蜘蛛池模板: 石景山区| 前郭尔| 靖远县| 禄丰县| 咸宁市| 巴中市| 沁水县| 公主岭市| 旅游| 尼玛县| 长丰县| 同德县| 上蔡县| 莎车县| 五台县| 绵竹市| 崇文区| 太湖县| 都匀市| 酒泉市| 青龙| 镇宁| 榕江县| 固镇县| 平顺县| 巴彦淖尔市| 新源县| 澄城县| 金川县| 唐河县| 梅河口市| 东阳市| 二连浩特市| 五寨县| 凤冈县| 清流县| 西安市| 周口市| 永善县| 马关县| 迭部县|