公告
日歷
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
---|
27 | 28 | 29 | 30 | 31 | 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 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|
導(dǎo)航
隨筆分類(86)
隨筆檔案(85)
搜索
最新評(píng)論

閱讀排行榜
評(píng)論排行榜
|
最近花了一個(gè)多月的時(shí)間,完成了一個(gè)微不足道的小東西,之所以花了這么長(zhǎng)的時(shí)間,主要是對(duì)hibernate的運(yùn)用不是很熟練。以至于出現(xiàn)了各種各式各樣的異常。 1。其中時(shí)間最長(zhǎng)的異常是無(wú)錯(cuò)誤信息的異常。表現(xiàn)是數(shù)據(jù)庫(kù)死鎖。有經(jīng)驗(yàn)的人當(dāng)然能猜得到這是事務(wù)處理不當(dāng)造成的,但由于沒(méi)有經(jīng)驗(yàn), 我花費(fèi)了一個(gè)星期的時(shí)間才改正。 2。最奇怪的一個(gè)異常是:hibernate樂(lè)觀鎖異常。.hibernate3.HibernateOptimisticLockingFailureException: Unexpected row count: 2 expected: 1 我用的是hibernate3,對(duì)數(shù)據(jù)庫(kù)數(shù)據(jù)的更新是默認(rèn)的樂(lè)觀鎖。因?yàn)樗巧鷣?lái)就相當(dāng)樂(lè)觀的,不考慮我們這種新手常犯的錯(cuò)誤,數(shù)據(jù)關(guān)聯(lián)重復(fù)。 比如:從數(shù)據(jù)庫(kù)里取出一個(gè)對(duì)象,然后給它重新賦值,然后Update,如果其他表和它相關(guān),而且有重復(fù)的記錄,就會(huì)報(bào)這樣的錯(cuò)。解決方法是想辦法不讓其他表的相關(guān)數(shù)據(jù)記錄重復(fù)就可以解決。 3。我遇到的另一個(gè)不常見(jiàn)的異常:UncategorizedSQLException錯(cuò)誤原因,mssql中的text型字段為空值,將他加上默認(rèn)值后恢復(fù)正常,具體原因不太清楚。 org.springframework.jdbc.UncategorizedSQLException
評(píng)論:
-
# re: 關(guān)于hibernate的樂(lè)觀鎖異常
Posted @ 2006-09-15 14:59
真是很復(fù)雜啊,你能自己解決這個(gè)bug我真的很佩服,除了崇拜就是佩服啦。嘿嘿。加油哦 回復(fù) 更多評(píng)論
-
# re: 關(guān)于hibernate的樂(lè)觀鎖異常
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");
} 回復(fù) 更多評(píng)論
-
# re: 關(guān)于hibernate的樂(lè)觀鎖異常
Posted @ 2006-09-15 15:25
我也遇到過(guò),是在刪除數(shù)據(jù)的時(shí)候,不過(guò)不是每次都出這樣的錯(cuò)誤,有的時(shí)候hibernate的錯(cuò)誤怪怪的,不過(guò)畢竟hibernate還是最好的 回復(fù) 更多評(píng)論
-
# re: 關(guān)于hibernate的樂(lè)觀鎖異常
Posted @ 2006-09-18 16:57
//----使用jtds驅(qū)動(dòng)吧--------------------
<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> 回復(fù) 更多評(píng)論
-
# re: 關(guān)于hibernate的樂(lè)觀鎖異常
Posted @ 2006-09-18 16:58
@智者無(wú)
在郵箱里有驅(qū)動(dòng)包 回復(fù) 更多評(píng)論
-
# re: 關(guān)于hibernate的樂(lè)觀鎖異常
Posted @ 2006-09-19 11:37
DWR中DWRUtil學(xué)習(xí)
這些功能函數(shù)在下面這個(gè)網(wǎng)址都有示例,這里只是把他們用中文解釋,方便查找.
http://getahead.ltd.uk/dwr/browser/util
DWRUtil.getText(id)
這個(gè)函數(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.
這個(gè)函數(shù)主要的作用是取到當(dāng)前select的顯示值即<option value>xxx</option>中xxx的內(nèi)容
DWRUtil.getValue(id) 用來(lái)得到<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.
這個(gè)函數(shù)能用于多個(gè)元素input type =textarea,text,Form button,formbutton,password(明文),
Fancy button等元素,主要可以屏蔽原來(lái)對(duì)select元素getValue操作帶來(lái)的不便
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ù)主要是一次完成多個(gè)元素的getValue()操作,并將value的結(jié)果以js對(duì)象的形式封裝起來(lái)返回,參數(shù)是一個(gè)js對(duì)象,其中包含了希望取到value的element id
e.g
{ div:null, textarea:null, select:null, text:null, password:null, formbutton:null, button:null}
詳細(xì)參考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.
在一個(gè)form表單中敲回車鍵將導(dǎo)致表單被遞交,這往往不是我們希望看到的.但是很多瀏覽器對(duì)這個(gè)事件的處理是不統(tǒng)一的,這個(gè)函數(shù)就是為了消除這個(gè)不統(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).
在一個(gè)input元素中選擇一個(gè)范圍的字符串,可以查看
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.
主要是為了設(shè)值,屏蔽了select元素設(shè)值的問(wèn)題,對(duì)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對(duì)應(yīng),傳入js對(duì)象,將對(duì)象中的value傳給相應(yīng)的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ù)主要用來(lái)調(diào)試,傳入元素的id,調(diào)試的degree將顯示DOM信息
此函數(shù)有第三個(gè)參數(shù),用于聲明初始化,包含第三個(gè)參數(shù)的調(diào)用不應(yīng)該為使用,因?yàn)檫@個(gè)函數(shù)將來(lái)會(huì)改變
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.
你必須在頁(yè)面加載完成后(body onload事件)調(diào)用這個(gè)函數(shù),因?yàn)樗鼤?huì)創(chuàng)建一個(gè)div,來(lái)包含一些消息.類似gmail的message模式的東西.為了達(dá)到在頁(yè)面加載完成后來(lái)操作,
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>
該參考頁(yè)面給出了2個(gè)類似的文字圖片實(shí)現(xiàn).
DWRUtil.addOptions() 用返回的集合來(lái)填充select元素
多種實(shí)現(xiàn),詳細(xì)參考http://getahead.ltd.uk/dwr/browser/lists
DWRUtil.addRows() 返回的集合來(lái)填充table元素,或者tbody更為合適
回復(fù) 更多評(píng)論
-
# re: 關(guān)于hibernate的樂(lè)觀鎖異常
Posted @ 2009-05-26 10:15
還是沒(méi)有看到你的hibernate的樂(lè)觀鎖異常的解決方法 回復(fù) 更多評(píng)論
|