公告
日歷
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
---|
27 | 28 | 29 | 30 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|
導航
隨筆分類(86)
隨筆檔案(85)
搜索
最新評論

閱讀排行榜
評論排行榜
|
最近花了一個多月的時間,完成了一個微不足道的小東西,之所以花了這么長的時間,主要是對hibernate的運用不是很熟練。以至于出現了各種各式各樣的異常。 1。其中時間最長的異常是無錯誤信息的異常。表現是數據庫死鎖。有經驗的人當然能猜得到這是事務處理不當造成的,但由于沒有經驗, 我花費了一個星期的時間才改正。 2。最奇怪的一個異常是:hibernate樂觀鎖異常。.hibernate3.HibernateOptimisticLockingFailureException: Unexpected row count: 2 expected: 1 我用的是hibernate3,對數據庫數據的更新是默認的樂觀鎖。因為它是生來就相當樂觀的,不考慮我們這種新手常犯的錯誤,數據關聯重復。 比如:從數據庫里取出一個對象,然后給它重新賦值,然后Update,如果其他表和它相關,而且有重復的記錄,就會報這樣的錯。解決方法是想辦法不讓其他表的相關數據記錄重復就可以解決。 3。我遇到的另一個不常見的異常:UncategorizedSQLException錯誤原因,mssql中的text型字段為空值,將他加上默認值后恢復正常,具體原因不太清楚。 org.springframework.jdbc.UncategorizedSQLException
評論:
-
# re: 關于hibernate的樂觀鎖異常
Posted @ 2006-09-15 14:59
真是很復雜啊,你能自己解決這個bug我真的很佩服,除了崇拜就是佩服啦。嘿嘿。加油哦 回復 更多評論
-
# re: 關于hibernate的樂觀鎖異常
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
我也遇到過,是在刪除數據的時候,不過不是每次都出這樣的錯誤,有的時候hibernate的錯誤怪怪的,不過畢竟hibernate還是最好的 回復 更多評論
-
# re: 關于hibernate的樂觀鎖異常
Posted @ 2006-09-18 16:57
//----使用jtds驅動吧--------------------
<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
@智者無
在郵箱里有驅動包 回復 更多評論
-
# re: 關于hibernate的樂觀鎖異常
Posted @ 2006-09-19 11:37
DWR中DWRUtil學習
這些功能函數在下面這個網址都有示例,這里只是把他們用中文解釋,方便查找.
http://getahead.ltd.uk/dwr/browser/util
DWRUtil.getText(id)
這個函數只能用于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.
這個函數主要的作用是取到當前select的顯示值即<option value>xxx</option>中xxx的內容
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.
這個函數能用于多個元素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.
此函數主要是一次完成多個元素的getValue()操作,并將value的結果以js對象的形式封裝起來返回,參數是一個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表單中敲回車鍵將導致表單被遞交,這往往不是我們希望看到的.但是很多瀏覽器對這個事件的處理是不統一的,這個函數就是為了消除這個不統一的
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.
此函數主要用來調試,傳入元素的id,調試的degree將顯示DOM信息
此函數有第三個參數,用于聲明初始化,包含第三個參數的調用不應該為使用,因為這個函數將來會改變
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事件)調用這個函數,因為它會創建一個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個類似的文字圖片實現.
DWRUtil.addOptions() 用返回的集合來填充select元素
多種實現,詳細參考http://getahead.ltd.uk/dwr/browser/lists
DWRUtil.addRows() 返回的集合來填充table元素,或者tbody更為合適
回復 更多評論
-
# re: 關于hibernate的樂觀鎖異常
Posted @ 2009-05-26 10:15
還是沒有看到你的hibernate的樂觀鎖異常的解決方法 回復 更多評論
|