﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-软件艺术思考者-随笔分类-about hibernate</title><link>http://www.blogjava.net/zhanglijun33/category/17945.html</link><description>混沌，彷徨，立志，蓄势...</description><language>zh-cn</language><lastBuildDate>Thu, 23 Aug 2007 13:40:42 GMT</lastBuildDate><pubDate>Thu, 23 Aug 2007 13:40:42 GMT</pubDate><ttl>60</ttl><item><title>eclipse server tow run's models and others</title><link>http://www.blogjava.net/zhanglijun33/archive/2007/08/23/h2.html</link><dc:creator>智者无疆</dc:creator><author>智者无疆</author><pubDate>Thu, 23 Aug 2007 07:10:00 GMT</pubDate><guid>http://www.blogjava.net/zhanglijun33/archive/2007/08/23/h2.html</guid><wfw:comment>http://www.blogjava.net/zhanglijun33/comments/138845.html</wfw:comment><comments>http://www.blogjava.net/zhanglijun33/archive/2007/08/23/h2.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zhanglijun33/comments/commentRss/138845.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zhanglijun33/services/trackbacks/138845.html</trackback:ping><description><![CDATA[<p>1.我们平时使用的是debug模式，但有时候这种模式使得启动服务时间非常长，如果不存在类级的Bug，可以直接使用Run模式启动服务。通常可以很快的启动了。但下次再启动服务时，eclipse会使用上一次的启动模式，如果不知道这一点，我们就没办法重新使用debug模式启动了。在run模式下，我们在类里的修改不能立即被服务器识别，不能进行全部的调试。要想重新使用debug模式启动,先点窗口，再点视图，再点server，然后在出现的服务器视图里选择debug模式启动即可。</p>
<p>2.hiberate query.setDate('",newDate()),不能使sql进行时分秒级的比较.此时应该使用.setTimeStamp().</p>
<img src ="http://www.blogjava.net/zhanglijun33/aggbug/138845.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhanglijun33/" target="_blank">智者无疆</a> 2007-08-23 15:10 <a href="http://www.blogjava.net/zhanglijun33/archive/2007/08/23/h2.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于hibernate的乐观锁异常</title><link>http://www.blogjava.net/zhanglijun33/archive/2006/09/15/OptimisticLockingFailure.html</link><dc:creator>智者无疆</dc:creator><author>智者无疆</author><pubDate>Fri, 15 Sep 2006 06:41:00 GMT</pubDate><guid>http://www.blogjava.net/zhanglijun33/archive/2006/09/15/OptimisticLockingFailure.html</guid><wfw:comment>http://www.blogjava.net/zhanglijun33/comments/69885.html</wfw:comment><comments>http://www.blogjava.net/zhanglijun33/archive/2006/09/15/OptimisticLockingFailure.html#Feedback</comments><slash:comments>7</slash:comments><wfw:commentRss>http://www.blogjava.net/zhanglijun33/comments/commentRss/69885.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zhanglijun33/services/trackbacks/69885.html</trackback:ping><description><![CDATA[最近花了一个多月的时间，完成了一个微不足道的小东西，之所以花了这么长的时间，主要是对hibernate的运用不是很熟练。以至于出现了各种各式各样的异常。<br />1。其中时间最长的异常是无错误信息的异常。表现是数据库死锁。有经验的人当然能猜得到这是事务处理不当造成的，但由于没有经验，<br />我花费了一个星期的时间才改正。<br />2。最奇怪的一个异常是：hibernate乐观锁异常。.hibernate3.HibernateOptimisticLockingFailureException: Unexpected row count: 2 expected: 1<br />我用的是hibernate3,对数据库数据的更新是默认的乐观锁。因为它是生来就相当乐观的，不考虑我们这种新手常犯的错误，数据关联重复。<br />比如：从数据库里取出一个对象，然后给它重新赋值，然后Update，如果其他表和它相关，而且有重复的记录，就会报这样的错。解决方法是想办法不让其他表的相关数据记录重复就可以解决。<br />3。我遇到的另一个不常见的异常：UncategorizedSQLException错误原因，mssql中的text型字段为空值，将他加上默认值后恢复正常，具体原因不太清楚。<br />org.springframework.jdbc.UncategorizedSQLException<br /><img src ="http://www.blogjava.net/zhanglijun33/aggbug/69885.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhanglijun33/" target="_blank">智者无疆</a> 2006-09-15 14:41 <a href="http://www.blogjava.net/zhanglijun33/archive/2006/09/15/OptimisticLockingFailure.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>最近遇到了hibernate的一个问题</title><link>http://www.blogjava.net/zhanglijun33/archive/2006/08/17/question1.html</link><dc:creator>智者无疆</dc:creator><author>智者无疆</author><pubDate>Thu, 17 Aug 2006 06:07:00 GMT</pubDate><guid>http://www.blogjava.net/zhanglijun33/archive/2006/08/17/question1.html</guid><wfw:comment>http://www.blogjava.net/zhanglijun33/comments/64114.html</wfw:comment><comments>http://www.blogjava.net/zhanglijun33/archive/2006/08/17/question1.html#Feedback</comments><slash:comments>8</slash:comments><wfw:commentRss>http://www.blogjava.net/zhanglijun33/comments/commentRss/64114.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zhanglijun33/services/trackbacks/64114.html</trackback:ping><description><![CDATA[
		<p>这几天一直没有更新我的博客是因为我遇到了一个棘手的问题,这是我编程以来困扰我时间最长的一个问题：从周一下午一直到现在。如果哪位高手有这方面的经验,请不吝指教:<br />这是个关于hibernate方面的问题:<br /><span class="tpc_content"><font size="2">我的数据库关联较多,hbm.xml是用myeclipse自动生成的.dao是spring的,也是myeclipse自动生成的.在用hibernate向数据库插入数据的时候,第一次执行还比较顺利,但把同样的数据再次插入的时候,代码就走不动了.(主键是自增长的,插入时不设值),但当我重启tomcat后,第一次执行插入又能插入了,但第二次执行的时候又走不动了...就这样周而复始.<br />我测试后发现经常被卡住的语句是类似下面的语句:<br />(某类)beanDAO.findByExample(某类实例).get(0);<br />请各位抽空看看.谢谢.</font></span><br /><span class="tpc_content"><font size="2">大家可以凭经验来判断一下这个问题.不用看代码.因为hbm.mxl 和dao都是myeclipse自动生成的,我没有改.<br />而程序中经常出错就这句.(某类)beanDAO.findByExample(某类实例).get(0);<br /><br /><br />现在我对这个问题总算有点思路了。但还没实现，请高手指教。</font></span></p>
<img src ="http://www.blogjava.net/zhanglijun33/aggbug/64114.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhanglijun33/" target="_blank">智者无疆</a> 2006-08-17 14:07 <a href="http://www.blogjava.net/zhanglijun33/archive/2006/08/17/question1.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Hibernate+Spring 对DAO的处理实列!</title><link>http://www.blogjava.net/zhanglijun33/archive/2006/07/25/goodacticle.html</link><dc:creator>智者无疆</dc:creator><author>智者无疆</author><pubDate>Tue, 25 Jul 2006 03:23:00 GMT</pubDate><guid>http://www.blogjava.net/zhanglijun33/archive/2006/07/25/goodacticle.html</guid><wfw:comment>http://www.blogjava.net/zhanglijun33/comments/59954.html</wfw:comment><comments>http://www.blogjava.net/zhanglijun33/archive/2006/07/25/goodacticle.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zhanglijun33/comments/commentRss/59954.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zhanglijun33/services/trackbacks/59954.html</trackback:ping><description><![CDATA[
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td valign="top" align="left" width="100%">
										<div class="diaryTitleBg"> </div>
								</td>
						</tr>
						<tr>
								<td valign="top" align="left" width="100%">
										<div class="diarybody">
												<span class="postbody">引用"Spring"手册上的话说: Hibernate+Spring显然是天生的结合.<br /><br />下面是我用spring处理的一个HibernateDAO实例,可以看到,代码量大大减少了.<br /><br /></span>
												<table cellspacing="1" cellpadding="3" width="90%" align="center" border="0">
														<tbody>
																<tr>
																		<td>
																				<span class="genmed">
																						<b>java代码: </b>
																				</span>
																		</td>
																</tr>
																<tr>
																		<td class="code">
																				<div style="FONT-FAMILY: 'Courier New', Courier, monospace">
																						<br />
																						<br />
																						<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">package</span> infoweb.<span style="COLOR: #000000">dao</span>;<br /><br /><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">import</span> java.<span style="COLOR: #000000">util</span>.<span style="COLOR: #000000">List</span>;<br /><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">import</span> java.<span style="COLOR: #000000">util</span>.<span style="COLOR: #000000">Iterator</span>;<br /><br /><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">import</span> infoweb.<span style="COLOR: #000000">pojo</span>.<span style="COLOR: #000000">Info</span>;<br /><br /><br /><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">import</span> net.<span style="COLOR: #000000">sf</span>.<span style="COLOR: #000000">hibernate</span>.<span style="COLOR: #000000">HibernateException</span>;<br /><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">import</span> net.<span style="COLOR: #000000">sf</span>.<span style="COLOR: #000000">hibernate</span>.<span style="COLOR: #000000">Query</span>;<br /><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">import</span> net.<span style="COLOR: #000000">sf</span>.<span style="COLOR: #000000">hibernate</span>.<span style="COLOR: #000000">Session</span>;<br /><br /><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">import</span> org.<span style="COLOR: #000000">springframework</span>.<span style="COLOR: #000000">orm</span>.<span style="COLOR: #000000">hibernate</span>.<span style="COLOR: #000000">HibernateCallback</span>;<br /><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">import</span> org.<span style="COLOR: #000000">springframework</span>.<span style="COLOR: #000000">orm</span>.<span style="COLOR: #000000">hibernate</span>.<span style="COLOR: #000000">support</span>.<span style="COLOR: #000000">HibernateDaoSupport</span>;<br /><br /><br /><span style="COLOR: #6666ff">/**<br />* &lt;p&gt;Title: &lt;/p&gt;<br />* &lt;p&gt;Description: &lt;/p&gt;<br />* &lt;p&gt;Copyright: Copyright (c) 2004&lt;/p&gt;<br />* &lt;p&gt;Company: &lt;/p&gt;<br />* @author 段洪杰<br />* @version 1.0<br />*/</span><br /><br /><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">class</span> InfoDAOImpl <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">extends</span> HibernateDaoSupport <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">implements</span> IInfoDAO <span style="COLOR: #000000">{</span><br />  <span style="COLOR: #6666ff">/**<br />   * 构造函数<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span> InfoDAOImpl<span style="COLOR: #000000">()</span><span style="COLOR: #000000">{</span><br />    super<span style="COLOR: #000000">()</span>;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 增加记录<br />   * @param info Info<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">void</span> setInfo<span style="COLOR: #000000">(</span>Info info<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">save(</span>info<span style="COLOR: #000000">)</span>;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 通过ID取得记录<br />   * @param id String<br />   * @return Info<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span> Info getInfoById<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> id<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    Info info = <span style="COLOR: #000000">(</span>Info<span style="COLOR: #000000">)</span> getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">load(</span>Info.<span style="COLOR: #000000">class</span>, id<span style="COLOR: #000000">)</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> info;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 修改记录<br />   * @param Info info<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">void</span> modifyInfo<span style="COLOR: #000000">(</span>Info info<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">update(</span>info<span style="COLOR: #000000">)</span>;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 删除记录<br />   * @param Info info<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">void</span> removeInfo<span style="COLOR: #000000">(</span>Info info<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">delete(</span>info<span style="COLOR: #000000">)</span>;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">////////////////////////////////////////////////////////</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">/////以下部份不带审核功能                              ///</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">////////////////////////////////////////////////////////</span><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取记录总数<br />   * @return int<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> getInfosCount<span style="COLOR: #000000">()</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> count = <span style="COLOR: #000000" ?="">0</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString = "select count<span style="COLOR: #000000">(</span>*<span style="COLOR: #000000">)</span> from Info";<br />    count = <span style="COLOR: #000000">((</span><span style="COLOR: #aaaadd" ?="">Integer</span><span style="COLOR: #000000">)</span> getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">iterate(</span>queryString<span style="COLOR: #000000">)</span>.<span style="COLOR: #000000">next())</span>.<br />            <span style="COLOR: #000000">intValue()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> count;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取所有记录集合<br />   * @return Iterator<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Iterator</span> getAllInfos<span style="COLOR: #000000">()</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString = " select info from Info as info order by info.<span style="COLOR: #000000">id</span> desc";<br />    <span style="COLOR: #aaaadd" ?="">List</span> list = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">find(</span>queryString<span style="COLOR: #000000">)</span>;<br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> iterator;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取记录集合<br />   * @return Iterator<br />   * @param int position, int length<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Iterator</span> getInfos<span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> position, <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> length<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString = " select info from Info as info order by info.<span style="COLOR: #000000">id</span> desc";<br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的起始点</span><br />    query.<span style="COLOR: #000000">setFirstResult(</span>position<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的长度</span><br />    query.<span style="COLOR: #000000">setMaxResults(</span>length<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> iterator;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取第一条记录<br />   * @throws Exception<br />   * @return Station<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span> Info getFirstInfo<span style="COLOR: #000000">()</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    Info info = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString = "select info from Info as info order by info.<span style="COLOR: #000000">id</span> desc";<br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">if</span><span style="COLOR: #000000">(</span>iterator.<span style="COLOR: #000000">hasNext())</span><span style="COLOR: #000000">{</span><br />      info = <span style="COLOR: #000000">(</span>Info<span style="COLOR: #000000">)</span> iterator.<span style="COLOR: #000000">next()</span>;<br />    <span style="COLOR: #000000">}</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> info;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取最后一条记录<br />   * @throws Exception<br />   * @return Station<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span> Info getLastInfo<span style="COLOR: #000000">()</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    Info info = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString = "select info from Info as info order by info.<span style="COLOR: #000000">id</span> asc";<br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">if</span><span style="COLOR: #000000">(</span>iterator.<span style="COLOR: #000000">hasNext())</span><span style="COLOR: #000000">{</span><br />      info = <span style="COLOR: #000000">(</span>Info<span style="COLOR: #000000">)</span> iterator.<span style="COLOR: #000000">next()</span>;<br />    <span style="COLOR: #000000">}</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> info;<br /><br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">////////////////////////////////////////////////////////</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">///// 以下部份表中要有特定字段才能Õ吩诵袪 牳鋈撕推笠禒    ///</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">////////////////////////////////////////////////////////</span><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取符合条件记录总数, [表中要有 isperson 字段]<br />   * @return int<br />   * @param int isPerson<br />   */</span><br /><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> getInfosCountByIsperson<span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> isPerson<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> count = <span style="COLOR: #000000" ?="">0</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString =<br />        "select count<span style="COLOR: #000000">(</span>*<span style="COLOR: #000000">)</span> from Info as info where info.<span style="COLOR: #000000">isperson</span> =" + isPerson;<br />    count = <span style="COLOR: #000000">((</span><span style="COLOR: #aaaadd" ?="">Integer</span><span style="COLOR: #000000">)</span> getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">iterate(</span>queryString<span style="COLOR: #000000">)</span>.<span style="COLOR: #000000">next())</span>.<br />            <span style="COLOR: #000000">intValue()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> count;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取所有符合条件记录集合, 模糊查询条件.[表中要有 isperson 字段]<br />   * @return Iterator<br />   * @param int isPerson<br />   */</span><br /><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Iterator</span> getAllInfosByIsperson<span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> isPerson<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString = " select info from Info as info where info.<span style="COLOR: #000000">isperson</span> =" +<br />                         isPerson + " order by info.<span style="COLOR: #000000">id</span> desc";<br />    <span style="COLOR: #aaaadd" ?="">List</span> list = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">find(</span>queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> iterator;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取符合条件记录集合, 模糊查询条件.[表中要有 isperson 字段]<br />   * @return Iterator<br />   * @param int isPerson,int position, int length<br />   */</span><br /><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Iterator</span> getInfosByIsperson<span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> isPerson, <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> position, <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> length<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><br />      <span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString = " select info from Info as info where info.<span style="COLOR: #000000">isperson</span> =" +<br />                         isPerson + " order by info.<span style="COLOR: #000000">id</span> desc";<br />    <span style="COLOR: #6666ff">//创建查询</span><br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的起始点</span><br />    query.<span style="COLOR: #000000">setFirstResult(</span>position<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的长度</span><br />    query.<span style="COLOR: #000000">setMaxResults(</span>length<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> iterator;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">////////////////////////////////////////////////////////</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">///// 以下部份表中要有特定字段才能Õ吩诵袪  查询部份      ///</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">///////////////////////////////////////////////////////</span><br />  <span style="COLOR: #6666ff">/**<br />   * 取符合条件记录总数, 模糊查询条件.[表中要有 title 字段]<br />   * @return int<br />   * @param String text<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> getInfosCount<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> text<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> count = <span style="COLOR: #000000" ?="">0</span>;<br />    count = <span style="COLOR: #000000">((</span><span style="COLOR: #aaaadd" ?="">Integer</span><span style="COLOR: #000000">)</span> getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">iterate(</span><br />        "select count<span style="COLOR: #000000">(</span>*<span style="COLOR: #000000">)</span> from Info as info where info.<span style="COLOR: #000000">title</span> like <span style="COLOR: #0000ff">'%" + text +<br />        "%'</span>"<span style="COLOR: #000000">)</span>.<span style="COLOR: #000000">next())</span>.<span style="COLOR: #000000">intValue()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> count;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取所有符合条件记录集合, 模糊查询条件.[表中要有 title 字段]<br />   * @return Iterator<br />   * @param String text<br />   */</span><br /><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Iterator</span> getAllInfos<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> text<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString =<br />        " select info from Info as info where info.<span style="COLOR: #000000">title</span> like <span style="COLOR: #0000ff">'%" + text +<br />        "%'</span> order by info.<span style="COLOR: #000000">id</span> desc";<br />    <span style="COLOR: #6666ff">//创建查询</span><br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> iterator;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取符合条件记录集合, 模糊查询条件.[表中要有 title 字段]<br />   * @return Iterator<br />   * @param String text,int position, int length<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Iterator</span> getInfos<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> text, <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> position, <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> length<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><br />      <span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString =<br />        " select info from Info as info where info.<span style="COLOR: #000000">title</span> like <span style="COLOR: #0000ff">'%" + text +<br />        "%'</span> order by info.<span style="COLOR: #000000">id</span> desc";<br /><br />    <span style="COLOR: #6666ff">//创建查询</span><br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的起始点</span><br />    query.<span style="COLOR: #000000">setFirstResult(</span>position<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的长度</span><br />    query.<span style="COLOR: #000000">setMaxResults(</span>length<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> iterator;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">////////////////////////////////////////////////////////</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">///// 以下部份表中要有特定字段才能Õ吩诵袪 犠⒉嵯喙貭     ///</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">////////////////////////////////////////////////////////</span><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取符合条件记录总数.[ 表中要有 registername 字段]<br />   * @return int<br />   * @param String text<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> getInfosCountByRegisterName<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> registerName<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> count = <span style="COLOR: #000000" ?="">0</span>;<br />    count = <span style="COLOR: #000000">((</span><span style="COLOR: #aaaadd" ?="">Integer</span><span style="COLOR: #000000">)</span> getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">iterate(</span><br />        "select count<span style="COLOR: #000000">(</span>*<span style="COLOR: #000000">)</span> from Info as info where info.<span style="COLOR: #000000">registername</span> = <span style="COLOR: #0000ff">'" +<br />        registerName + "'</span>"<span style="COLOR: #000000">)</span>.<span style="COLOR: #000000">next())</span>.<span style="COLOR: #000000">intValue()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> count;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 通过注册名取得一条记录,如有多条,只取第一条.[表中要有 registername字段]<br />   * @param registername String<br />   * @return Info<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span> Info getInfoByRegisterName<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> registerName<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    Info info = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString =<br />        " select info from Info as info where info.<span style="COLOR: #000000">registername</span>=<span style="COLOR: #0000ff">'" +<br />        registerName + "'</span> order by info.<span style="COLOR: #000000">id</span> desc";<br />    <span style="COLOR: #6666ff">//创建查询</span><br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">if</span><span style="COLOR: #000000">(</span>iterator.<span style="COLOR: #000000">hasNext())</span><span style="COLOR: #000000">{</span><br />      info = <span style="COLOR: #000000">(</span>Info<span style="COLOR: #000000">)</span> iterator.<span style="COLOR: #000000">next()</span>;<br />    <span style="COLOR: #000000">}</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> info;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 通过注册名取得所有记录集合.[表中要有 registername字段]<br />   * @param registername String<br />   * @return Iterator<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Iterator</span> getAllInfosByRegisterName<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> registerName<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><br />      <span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString =<br />        " select info from Info as info where info.<span style="COLOR: #000000">registername</span>=<span style="COLOR: #0000ff">'" +<br />        registerName + "'</span> order by info.<span style="COLOR: #000000">id</span> desc";<br />    <span style="COLOR: #6666ff">//创建查询</span><br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> iterator;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 通过注册名取得记录列表.[表中要有 registername字段]<br />   * @param registername String<br />   * @return Iterator<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Iterator</span> getInfosByRegisterName<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> registerName, <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> position,<br />                                         <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> length<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString =<br />        " select info from Info as info where info.<span style="COLOR: #000000">registername</span>=<span style="COLOR: #0000ff">'" +<br />        registerName + "'</span> order by info.<span style="COLOR: #000000">id</span> desc";<br />    <span style="COLOR: #6666ff">//创建查询</span><br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的起始点</span><br />    query.<span style="COLOR: #000000">setFirstResult(</span>position<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的长度</span><br />    query.<span style="COLOR: #000000">setMaxResults(</span>length<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> iterator;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">////////////////////////////////////////////////////////</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">///// 以下部份表中要有特定字段才能Õ吩诵袪   犑餍桶婵闋    ///</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">////////////////////////////////////////////////////////</span><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取记录总数.[ 表中要有 board_id 字段]<br />   * @return int<br />   * @param String boardId<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> getInfosCountByBoard<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> boardId<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> count = <span style="COLOR: #000000" ?="">0</span>;<br /><br />    count = <span style="COLOR: #000000">((</span><span style="COLOR: #aaaadd" ?="">Integer</span><span style="COLOR: #000000">)</span> getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">iterate(</span><br />        "select count<span style="COLOR: #000000">(</span>*<span style="COLOR: #000000">)</span> from Info as info where info.<span style="COLOR: #000000">boardId</span> = <span style="COLOR: #0000ff">'" + boardId +<br />        "'</span>"<span style="COLOR: #000000">)</span>.<span style="COLOR: #000000">next())</span>.<span style="COLOR: #000000">intValue()</span>;<br /><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> count;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 通过版块名取得所有记录集合.[表中要有 board_id字段]<br />   * @param BoardId String<br />   * @return Iterator<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Iterator</span> getAllInfosByBoard<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> boardId<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString = " select info from Info as info where info.<span style="COLOR: #000000">boardId</span>=<span style="COLOR: #0000ff">'" +<br />                         boardId + "'</span> order by info.<span style="COLOR: #000000">id</span> desc";<br />    <span style="COLOR: #6666ff">//创建查询</span><br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> iterator;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 通过版块名取得记录列表.[表中要有 board_id字段]<br />   * @param BoardId String<br />   * @return Iterator<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Iterator</span> getInfosByBoard<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> boardId, <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> position, <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> length<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><br />      <span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString = " select info from Info as info where info.<span style="COLOR: #000000">boardId</span>=<span style="COLOR: #0000ff">'" +<br />                         boardId + "'</span> order by info.<span style="COLOR: #000000">id</span> desc";<br /><br />    <span style="COLOR: #6666ff">//创建查询</span><br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的起始点</span><br />    query.<span style="COLOR: #000000">setFirstResult(</span>position<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的长度</span><br />    query.<span style="COLOR: #000000">setMaxResults(</span>length<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br /><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> iterator;<br /><br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取符合条件记录总数.[ 表中要有 board_id 字段,title]  模糊查询title<br />   * @return int<br />   * @param String boardId ,String text<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> getInfosCountByBoard<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> boardId, <span style="COLOR: #aaaadd" ?="">String</span> text<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> count = <span style="COLOR: #000000" ?="">0</span>;<br /><br />    count = <span style="COLOR: #000000">((</span><span style="COLOR: #aaaadd" ?="">Integer</span><span style="COLOR: #000000">)</span> getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">iterate(</span><br />        "select count<span style="COLOR: #000000">(</span>*<span style="COLOR: #000000">)</span> from Info as info where info.<span style="COLOR: #000000">boardId</span>=<span style="COLOR: #0000ff">'" + boardId +<br />        "'</span> and info.<span style="COLOR: #000000">title</span> like <span style="COLOR: #0000ff">'%" + text + "%'</span>"<span style="COLOR: #000000">)</span>.<span style="COLOR: #000000">next())</span>.<span style="COLOR: #000000">intValue()</span>;<br /><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> count;<br /><br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 通过版块名取得记录列表.[表中要有 board_id字段]  模糊查询title<br />   * @param String boardID,int position, int length<br />   * @return Iterator<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Iterator</span> getInfosByBoard<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> boardId, <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> position, <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> length,<br />                                  <span style="COLOR: #aaaadd" ?="">String</span> text<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString = " select info from Info as info where info.<span style="COLOR: #000000">boardId</span>=<span style="COLOR: #0000ff">'" +<br />                         boardId + "'</span> and info.<span style="COLOR: #000000">title</span> like <span style="COLOR: #0000ff">'%" + text +<br />                         "%'</span> order by info.<span style="COLOR: #000000">id</span> desc";<br /><br />    <span style="COLOR: #6666ff">//创建查询</span><br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的起始点</span><br />    query.<span style="COLOR: #000000">setFirstResult(</span>position<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的长度</span><br />    query.<span style="COLOR: #000000">setMaxResults(</span>length<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> iterator;<br /><br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">////////////////////////////////////////////////////////</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">/////以下部份带有审核功能                              ///</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">////////////////////////////////////////////////////////</span><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取记录总数<br />   * @return int<br />   * @param int isAuditing<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> getInfosCount<span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> isAuditing<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #990066; FON: " border="0" cellspacing="0" cellpadding="0" align="center" 468?=""></span></div>
																		</td>
																</tr>
																<tr>
																		<td>
																				<script src="http://www.blogbus.com/ads/ads.js" type="text/javascript">
																				</script>
																		</td>
																</tr>
														</tbody>
												</table>
										</div>
								</td>
						</tr>
				</tbody>
		</table>
<img src ="http://www.blogjava.net/zhanglijun33/aggbug/59954.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhanglijun33/" target="_blank">智者无疆</a> 2006-07-25 11:23 <a href="http://www.blogjava.net/zhanglijun33/archive/2006/07/25/goodacticle.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>spring,hibernate,struts应用中的错误及更正-（3）</title><link>http://www.blogjava.net/zhanglijun33/archive/2006/07/11/STRUTS3.html</link><dc:creator>智者无疆</dc:creator><author>智者无疆</author><pubDate>Tue, 11 Jul 2006 07:10:00 GMT</pubDate><guid>http://www.blogjava.net/zhanglijun33/archive/2006/07/11/STRUTS3.html</guid><wfw:comment>http://www.blogjava.net/zhanglijun33/comments/57650.html</wfw:comment><comments>http://www.blogjava.net/zhanglijun33/archive/2006/07/11/STRUTS3.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/zhanglijun33/comments/commentRss/57650.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zhanglijun33/services/trackbacks/57650.html</trackback:ping><description><![CDATA[这两天公司任务不紧，这样就给我不少做试验的机会和时间。今天的试验是在action里面写多个不同的方法，并且要得 到业务层的对象以便进一步处理数据。<br />首先我的action要继承DispatchAction.这样才能实现多个不同的方法放在一个action里。<br />2.在里面写入固定的方法：<br />public void setServlet(ActionServlet actionServlet){<br />   super.setServlet(actionServlet);<br />   ServletContext  servletContext =actionServlet.getServletContext();<br />  WebApplicationContext wac =  WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);<br />//然后就可以得到业务层的对象了。像我昨天说得那样做就行。（注：在这个方法里面可以得到多个不同对象，已经试验通过）<br />然后再一个得到service对象的方法，以供后面的方法使用。<br />3.多个jsp页面可以对应一个action吗？可以，已经试验通过。并且在struts_config.xml里面无须做任何改动。<br />4.myAction?method=addXX后面可以跟其他参数吗？可以，已经试验通过。<br />5，jsp向action发出请求的时候，为什么有时候出现空白异常？这时候你应该从两个方面进行检查<br />  1，检查你的struts_config.xml forwordname<br />   2以上经验是我苦想了一天才得到的。<img src ="http://www.blogjava.net/zhanglijun33/aggbug/57650.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhanglijun33/" target="_blank">智者无疆</a> 2006-07-11 15:10 <a href="http://www.blogjava.net/zhanglijun33/archive/2006/07/11/STRUTS3.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>struts,hibernate,spring应用过程中的错误及更正（每日更新）</title><link>http://www.blogjava.net/zhanglijun33/archive/2006/07/10/zongjie.html</link><dc:creator>智者无疆</dc:creator><author>智者无疆</author><pubDate>Mon, 10 Jul 2006 08:22:00 GMT</pubDate><guid>http://www.blogjava.net/zhanglijun33/archive/2006/07/10/zongjie.html</guid><wfw:comment>http://www.blogjava.net/zhanglijun33/comments/57522.html</wfw:comment><comments>http://www.blogjava.net/zhanglijun33/archive/2006/07/10/zongjie.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.blogjava.net/zhanglijun33/comments/commentRss/57522.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zhanglijun33/services/trackbacks/57522.html</trackback:ping><description><![CDATA[上接“jsp页面得到业务层的对象”<br />1.我现在想用org.springframework.orm.hibernate.HibernateTransactionManager来给业务对象织入事务管理方法。但在调试的时候却发生了异常:Error registering bean with name 'myTransactionManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml],系统在给myTransactionManager Bean注册的时候却找不到它的类。的确是很奇怪的问题，HibernateTransactionManager明明就在这儿摆着嘛，怎么系统就是找不到呢。经过几个小时的查找代码档案，发现原来我用的是Hibernate3版本。相应的org.springframework.orm.hibernate.HibernateTransactionManager也应该改成：org.springframework.orm.hibernate3.HibernateTransactionManager.汗！java程序员真累。<br />2.错误2，当我想在页面上得到织入事务管理的service对象时，又有一个错误来了：<br />org.apache.jasper.JasperException: $Proxy2<br />org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)<br />晕吧，代理人的待遇没问题了，可是它就是不给你做代理。经过在jsp页面上的排察：终于找到这一句：<br />   RealnewsService newsservice=(RealnewsService)wac.getBean("newsService");<br />它有什么问题吗？初学者看不出什么错误来，因为语法上一点错也没有，后来经高手指点才如梦初醒：<br />它的声明类型应该是相应的接口。这是spring一贯的风格，（但这至于让我出错吗？郁闷），好。到今天为址，我和关注我的博客的同学应该对spring应用程序的核心配置文件有了一定的理解了。<br />总结一句话：解决问题的方法是：来了问题不要怕，用朴素的理念和执著的态度去战胜bug  ;-)<img src ="http://www.blogjava.net/zhanglijun33/aggbug/57522.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhanglijun33/" target="_blank">智者无疆</a> 2006-07-10 16:22 <a href="http://www.blogjava.net/zhanglijun33/archive/2006/07/10/zongjie.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>