软件艺术思考者  
混沌,彷徨,立志,蓄势...
公告
日历
<2024年3月>
252627282912
3456789
10111213141516
17181920212223
24252627282930
31123456

导航

随笔分类(86)

随笔档案(85)

搜索

  •  

最新评论

阅读排行榜

评论排行榜

 
最近花了一个多月的时间,完成了一个微不足道的小东西,之所以花了这么长的时间,主要是对hibernate的运用不是很熟练。以至于出现了各种各式各样的异常。
1。其中时间最长的异常是无错误信息的异常。表现是数据库死锁。有经验的人当然能猜得到这是事务处理不当造成的,但由于没有经验,
我花费了一个星期的时间才改正。
2。最奇怪的一个异常是:hibernate乐观锁异常。.hibernate3.HibernateOptimisticLockingFailureException: Unexpected row count: 2 expected: 1
我用的是hibernate3,对数据库数据的更新是默认的乐观锁。因为它是生来就相当乐观的,不考虑我们这种新手常犯的错误,数据关联重复。
比如:从数据库里取出一个对象,然后给它重新赋值,然后Update,如果其他表和它相关,而且有重复的记录,就会报这样的错。解决方法是想办法不让其他表的相关数据记录重复就可以解决。
3。我遇到的另一个不常见的异常:UncategorizedSQLException错误原因,mssql中的text型字段为空值,将他加上默认值后恢复正常,具体原因不太清楚。
org.springframework.jdbc.UncategorizedSQLException
posted on 2006-09-15 14:41 智者无疆 阅读(4866) 评论(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
    我也遇到过,是在删除数据的时候,不过不是每次都出这样的错误,有的时候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的乐观锁异常  flash8627 Posted @ 2009-05-26 10:15
    还是没有看到你的hibernate的乐观锁异常的解决方法  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 
 
Copyright © 智者无疆 Powered by: 博客园 模板提供:沪江博客


   观音菩萨赞