??xml version="1.0" encoding="utf-8" standalone="yes"?>国产在线超碰,欧美久色视频,全国精品久久少妇http://www.aygfsteel.com/mstar/category/1162.html搞Y件开发就像被强奸,如果不能反抗,׃n受它吧!zh-cnTue, 27 Feb 2007 18:33:49 GMTTue, 27 Feb 2007 18:33:49 GMT60Hibernate3中取得多层数据的所产生的n+1 selects问题的解冟?/title><link>http://www.aygfsteel.com/mstar/archive/2005/09/30/14477.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Fri, 30 Sep 2005 01:12:00 GMT</pubDate><guid>http://www.aygfsteel.com/mstar/archive/2005/09/30/14477.html</guid><wfw:comment>http://www.aygfsteel.com/mstar/comments/14477.html</wfw:comment><comments>http://www.aygfsteel.com/mstar/archive/2005/09/30/14477.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mstar/comments/commentRss/14477.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mstar/services/trackbacks/14477.html</trackback:ping><description><![CDATA[其实q个问题在Hibernate in Action中已l有很多U解军_法了。但我觉得其中最好的办法是用Criteria的FetchMode来解冻I但是Hibernate in Action中写的很不详l。我昨晚试了好长旉来的到答案。下面ȝ一下?BR>需求这LQ我有四张表Qone,two,three,fourQ从one一直外键关联到four。结构如?BR><IMG height=296 alt=hibernatefetch.jpg src="http://www.aygfsteel.com/images/blogjava_net/mstar/pics20050930/hibernatefetch.jpg" width=502 border=0><BR>现在在Session中得到OneQƈ从One里一直取到Four里的内容。如果简单的用Session.get来实现是q样的?BR> <DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #000000">One one </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> (One)session.get(One.</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> Integer(</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">));<BR>        Iterator iterone </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> one.getTwos().iterator();<BR>        </SPAN><SPAN style="COLOR: #0000ff">while</SPAN><SPAN style="COLOR: #000000">(iterone.hasNext()){<BR>            Two two </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> (Two) iterone.next();<BR>            Iterator itertwo </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> two.getThrees().iterator();<BR>            </SPAN><SPAN style="COLOR: #0000ff">while</SPAN><SPAN style="COLOR: #000000">(itertwo.hasNext()){<BR>                Three three </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> (Three) itertwo.next();<BR>                three.getFours().size();                <BR>            }<BR>        }</SPAN></DIV>q样我在Session关闭后返回的One里是从One到Four的信息都有的?BR>然而这样做所D的结果是生成大量的SQL查询Q这是一个典型的n+1 Selects问题。如果系l结构层ơ多Q符合条件的记录多,那么HibernateZ生成的SQL查询是难以接受的?BR>对于q个例子生成的SQL是这L<BR>Hibernate: select one0_.c_one_id as c1_0_, one0_.c_one_text as c2_3_0_ from One one0_ where one0_.c_one_id=?<BR>Hibernate: select twos0_.c_one_id as c2_1_, twos0_.c_two_id as c1_1_, twos0_.c_two_id as c1_0_, twos0_.c_one_id as c2_2_0_, twos0_.c_two_text as c3_2_0_ from Two twos0_ where twos0_.c_one_id=?<BR>Hibernate: select threes0_.c_two_id as c2_1_, threes0_.c_three_id as c1_1_, threes0_.c_three_id as c1_0_, threes0_.c_two_id as c2_1_0_, threes0_.c_three_text as c3_1_0_ from Three threes0_ where threes0_.c_two_id=?<BR>Hibernate: select fours0_.c_three_id as c2_1_, fours0_.c_four_id as c1_1_, fours0_.c_four_id as c1_0_, fours0_.c_three_id as c2_0_0_, fours0_.c_four_text as c3_0_0_ from Four fours0_ where fours0_.c_three_id=?<BR>Hibernate: select fours0_.c_three_id as c2_1_, fours0_.c_four_id as c1_1_, fours0_.c_four_id as c1_0_, fours0_.c_three_id as c2_0_0_, fours0_.c_four_text as c3_0_0_ from Four fours0_ where fours0_.c_three_id=?<BR>Hibernate: select threes0_.c_two_id as c2_1_, threes0_.c_three_id as c1_1_, threes0_.c_three_id as c1_0_, threes0_.c_two_id as c2_1_0_, threes0_.c_three_text as c3_1_0_ from Three threes0_ where threes0_.c_two_id=?<BR>Hibernate: select fours0_.c_three_id as c2_1_, fours0_.c_four_id as c1_1_, fours0_.c_four_id as c1_0_, fours0_.c_three_id as c2_0_0_, fours0_.c_four_text as c3_0_0_ from Four fours0_ where fours0_.c_three_id=?<BR>Hibernate: select fours0_.c_three_id as c2_1_, fours0_.c_four_id as c1_1_, fours0_.c_four_id as c1_0_, fours0_.c_three_id as c2_0_0_, fours0_.c_four_text as c3_0_0_ from Four fours0_ where fours0_.c_three_id=?<BR>对于q样的问题,在没有Hibernate以前我们一般都用jdbc来做Q那L话我们其实用一个进?ơjoin的sql语句可以实玎ͼ但是q样解决也有问题Q就是返回的ResultSet中的数据非常多,而且杂ؕQ其实是从one到fourq排列的。对于这Ll果集我们要把它手动影射曑֯象结构也是一个很复杂的操作?BR>q好Hibernate3可以为我们做q些事情(我再一ơ被Hibernate的强大所震撼)?BR>上面的实现可以用Criteria来实玎ͼ<BR> <DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #000000">session </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> sessionFactory.openSession();<BR>        Criteria criteria </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> session.createCriteria(One.</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">);<BR>        criteria.add(Expression.eq(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">COneId</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> Integer(</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">)));<BR>        one </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> (One)criteria.setFetchMode(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">twos</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,FetchMode.JOIN).setFetchMode(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">twos.threes</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,FetchMode.JOIN).setFetchMode(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">twos.threes.fours</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,FetchMode.JOIN).uniqueResult();<BR>        session.close();</SPAN></DIV> <P>q里的重Ҏq句话criteria.setFetchMode(<SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">twos</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,FetchMode.JOIN).setFetchMode(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">twos.threes</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,FetchMode.JOIN).setFetchMode(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">twos.threes.fours</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,FetchMode.JOIN).uniqueResult();<BR>在用Criteria之前先设|FetchModeQ应为Criteria是动态生成sql语句的,所以生成的sql是一层层Join下去的?BR>setFetchModeQStringQModeQ第一个参数是association pathQ用"."来表C\径。这一点具体的例子很少Q文也没有写清楚。我也是试了很久才试出来的?BR>p个例子来所把因为取道第四层Q所以要q行三次setFetchMode<BR>W一ơ的路径是twosQ一位one中有two的Set。这个具体要更具hbm.xml的配|来定?BR>W二个\径就是twos.threes<BR>W三个就是twos.threes.fours<BR>一ơ类推,一层层增加的?BR>q样做法最l生成的SQL是这LQ?BR>Hibernate: select this_.c_one_id as c1_3_, this_.c_one_text as c2_3_3_, twos2_.c_one_id as c2_5_, twos2_.c_two_id as c1_5_, twos2_.c_two_id as c1_0_, twos2_.c_one_id as c2_2_0_, twos2_.c_two_text as c3_2_0_, threes3_.c_two_id as c2_6_, threes3_.c_three_id as c1_6_, threes3_.c_three_id as c1_1_, threes3_.c_two_id as c2_1_1_, threes3_.c_three_text as c3_1_1_, fours4_.c_three_id as c2_7_, fours4_.c_four_id as c1_7_, fours4_.c_four_id as c1_2_, fours4_.c_three_id as c2_0_2_, fours4_.c_four_text as c3_0_2_ from One this_ left outer join Two twos2_ on this_.c_one_id=twos2_.c_one_id left outer join Three threes3_ on twos2_.c_two_id=threes3_.c_two_id left outer join Four fours4_ on threes3_.c_three_id=fours4_.c_three_id where this_.c_one_id=?<BR>虽然很长但是只有一条SQL语句。性能要好很多。Hibernate的强大之处是它会把返回的ResultSet自动影射C的对象模型里面去。这׃ؓ我们省了很多事?BR><BR>看来Hibernate真是一个耐hd的Framework啊?BR></SPAN><SPAN style="COLOR: #000000"><BR>源码Q没什么东ѝ?BR><A href="http://www.aygfsteel.com/mstar/Files/mstar/HiberFetch2.rar">http://www.aygfsteel.com/Files/mstar/HiberFetch2.rar</A></P></SPAN><img src ="http://www.aygfsteel.com/mstar/aggbug/14477.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mstar/" target="_blank">黑灵</a> 2005-09-30 09:12 <a href="http://www.aygfsteel.com/mstar/archive/2005/09/30/14477.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Hibernate3中的更新与删?/title><link>http://www.aygfsteel.com/mstar/archive/2005/09/15/13130.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Thu, 15 Sep 2005 15:52:00 GMT</pubDate><guid>http://www.aygfsteel.com/mstar/archive/2005/09/15/13130.html</guid><wfw:comment>http://www.aygfsteel.com/mstar/comments/13130.html</wfw:comment><comments>http://www.aygfsteel.com/mstar/archive/2005/09/15/13130.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mstar/comments/commentRss/13130.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mstar/services/trackbacks/13130.html</trackback:ping><description><![CDATA[在Hibernate2中对某个表进行更新和删除Q必d把它Load出来Q在后更改,然后再保存?BR>q个q程对于扚w操作或者对于表关系比较复杂的情况,是很复杂的?BR>在Hibernate3中HQL语句中已l支持update 和delete ?BR>但是要注意的是update和delete的HQL不是面向对象的了。你用对象方式的语句q回会出错?BR>下面是一个简单的例子?BR>用对象的方式Q不用HQLQ?BR> <DIV style="BORDER-RIGHT: #000 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #000 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #000 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #000 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #000000">        Session session </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> getSession();<BR>        Customer host </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> (Customer) session.load(Customer.</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">,hostEmail);<BR>        Customer guest </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> (Customer)session.load(Customer.</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">,guestEmail);<BR>        ContactId id</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> ContactId(host,guest);<BR>        Contact contact </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> (Contact)<FONT size=3>session</FONT>.load(Contact.</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">,id);<BR>        RelationShip relation </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> (RelationShip)session.load(RelationShip.</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">, </SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">);<BR>        contact.setRelationShip(relation);<BR>        contact.setUpdateTime(Calendar.getInstance().getTime());<BR>        session.flush();<BR>        session.close();</SPAN></DIV>用HQLQ?BR> <DIV style="BORDER-RIGHT: #000 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #000 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #000 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #000 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #000000">        </SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">final</SPAN><SPAN style="COLOR: #000000"> String HQL_BADGUY_TO_FRIEND </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">update Contact set relation_id = 1, updateTime = :updateTime where host = :hostEmail and guest = :guestEmail</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><BR>        Session session </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> getSession();<BR>        Query query </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> session.createQuery(HQL_BADGUY_TO_FRIEND);<BR>        query.setString(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">hostEmail</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,hostEmail);<BR>        query.setString(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">guestEmail</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,guestEmail);<BR>        query.setDate(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">updateTime</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,Calendar.getInstance().getTime());<BR>        query.executeUpdate();<BR>        session.close();</SPAN></DIV>如果你把HQL写成q个样子Q?BR>update Contact as c set c.relationShip.relationId =1 ......<BR>反而会出错Q也是_你就按照native SQLdp了?BR>q有Q如果能使用q样的功?BR><STRONG>hibernate.query.factory_class  =  org.hibernate.hql.classic.ClassicQueryTranslatorFactory</STRONG><BR>q个Hibernate配置属性要不去掉,要不换成<STRONG>org.hibernate.hql.ast.ASTQueryTranslatorFactory</STRONG><BR>上面那个是支持Hibernate2的?BR>但是有一点要注意Q如果你用update语句来做的话Q可能生缓存同步问题,而且两种Ҏ最后Hibernate执行的语句差不多Q对于第一U方法Hibernate也是q成一条update语句Q当然因为我是根据主键来update的,如果扚w处理的话q是用Update HQL快?BR><img src ="http://www.aygfsteel.com/mstar/aggbug/13130.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mstar/" target="_blank">黑灵</a> 2005-09-15 23:52 <a href="http://www.aygfsteel.com/mstar/archive/2005/09/15/13130.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Could not initialize proxy - the owning Session was closedhttp://www.aygfsteel.com/mstar/archive/2005/09/05/12125.html黑灵黑灵Mon, 05 Sep 2005 15:57:00 GMThttp://www.aygfsteel.com/mstar/archive/2005/09/05/12125.htmlhttp://www.aygfsteel.com/mstar/comments/12125.htmlhttp://www.aygfsteel.com/mstar/archive/2005/09/05/12125.html#Feedback1http://www.aygfsteel.com/mstar/comments/commentRss/12125.htmlhttp://www.aygfsteel.com/mstar/services/trackbacks/12125.htmlHibernatecȝinitialize()静态方法用于在Session范围内显式初始化代理cd例,isInitialized()Ҏ用于判断代理cd例是否已l被初始化。例如:

tx = session.beginTransaction();
Customer customer=(Customer)session.load(Customer.class,new Long(1));
if(!Hibernate.isInitialized(customer))
Hibernate.initialize(customer);
tx.commit();
session.close();
customer.getName();

以上代码在Session范围内通过Hibernatecȝinitialize()Ҏ昑ּ初始化了Customer代理cd例,因此当Session关闭后,可以正常讉KCustomer游离对象?/FONT>



黑灵 2005-09-05 23:57 发表评论
]]>
iBatis实战结Q?/title><link>http://www.aygfsteel.com/mstar/archive/2005/08/23/10790.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Tue, 23 Aug 2005 05:59:00 GMT</pubDate><guid>http://www.aygfsteel.com/mstar/archive/2005/08/23/10790.html</guid><wfw:comment>http://www.aygfsteel.com/mstar/comments/10790.html</wfw:comment><comments>http://www.aygfsteel.com/mstar/archive/2005/08/23/10790.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mstar/comments/commentRss/10790.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mstar/services/trackbacks/10790.html</trackback:ping><description><![CDATA[<P><FONT color=#000000>头一ơ在目中用iBatisQ以前用qHibernate所以接受v来比较快Q但是iBatis和Hibernate在细节上q是有很多不同之处的?BR>在这文章里Q我主要ȝiBatis中一些容易生莫名其妙的错误的地斏V?BR>一?BR>      iBatis会对你写在xml中的sql语句q行优化。它不是d的按照你写的东西原封不动的执行。在q里我目前只发现了一点对于你的resultClass中没有的属性,即便是你写在select语句中有q个属性,它在执行的实C会去掉。返回的ResultSet中是没有的?BR>二?BR>      写在sql-map-config.xml里面的那些sqlMap的顺序不是随便怎么样都可以的。对于的A-sqlMap要用到B-sqlMap中定义的东西的时候,A一定要写在B前面。不然会报错Q说你B中有些什么东西找不到定义?BR>三?BR><insert id="..." parameterClass="..."><BR>       <selectKey resultClass="..." keyProperty="..." > <BR>         select ....<BR>       </selectKey> <BR>         .....<BR>         .....<BR></insert><BR>q是d生成主键~号q执行插入的Ҏ。在使用q个Ҏ的时候,你的parameterClass中一定要有与keyProperty对应的属性,q样ibatis会把select出来的编h回parameterClass中,然后再执行insert操作?BR>四?BR>      sqlMap中的定义是全局的,量不要出现重复的定义,如typeAliasQsql-id{等?/FONT></P><img src ="http://www.aygfsteel.com/mstar/aggbug/10790.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mstar/" target="_blank">黑灵</a> 2005-08-23 13:59 <a href="http://www.aygfsteel.com/mstar/archive/2005/08/23/10790.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一个困C我好几天的Hibernate+Spring的问题,是解决了吧Q?/title><link>http://www.aygfsteel.com/mstar/archive/2005/06/02/5485.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Thu, 02 Jun 2005 13:32:00 GMT</pubDate><guid>http://www.aygfsteel.com/mstar/archive/2005/06/02/5485.html</guid><wfw:comment>http://www.aygfsteel.com/mstar/comments/5485.html</wfw:comment><comments>http://www.aygfsteel.com/mstar/archive/2005/06/02/5485.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mstar/comments/commentRss/5485.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mstar/services/trackbacks/5485.html</trackback:ping><description><![CDATA[String hql = "from TradeRecord as tr where tr.TradeTime>= :startTime and tr.TradeTime <= :endTime and tr.CustomerId =:cid";<BR>  String[] params = { "startTime", "endTime", "cid" };<BR>  Object[] args = { startTime, endTime, new Long(cid) };<BR> List list= this.getHibernateTemplate().findByNamedParam(hql,params,args);<BR>q是你调用list中的对象的getҎQ如果这个getҎ需要lazy loadQ你看到如下异常:<BR> ERROR LazyInitializationException:19 - could not initialize proxy - the owning Session was closed<BR><BR>q个问题困扰的我都要x了?BR><BR>现在q样可以了Q?BR>Session session = this.getSession();<BR>  String hql = "from TradeRecord as tr where tr.TradeTime>= :startTime "<BR>    + "and tr.TradeTime <= :endTime and tr.CustomerId =:cid";<BR>  String[] params = { "startTime", "endTime", "cid" };<BR>  Object[] args = { startTime, endTime, new Long(cid) };<BR>  Query query = session.createQuery(hql);<BR>  query.setDate("startTime",startTime);<BR>  query.setDate("endTime",endTime);<BR>  query.setLong("cid", cid);<BR>  List list = query.list();<BR><BR>也就是说Q调用HibernateTemplate的findByNamedParamҎQ他在执行完以后会把session自动x?BR><BR>我现在在找源码看个究竟?BR><BR>q个问题虽然解决了,但是q不值得高兴Q因为我发现hibernate执行的SQL语句要比我用JDBC写的sql语句多很多。我很怀疑hibernate的效率?img src ="http://www.aygfsteel.com/mstar/aggbug/5485.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mstar/" target="_blank">黑灵</a> 2005-06-02 21:32 <a href="http://www.aygfsteel.com/mstar/archive/2005/06/02/5485.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>对于昨天User -- Friend关系的解冻Ihttp://www.aygfsteel.com/mstar/archive/2005/04/28/3888.html黑灵黑灵Thu, 28 Apr 2005 06:00:00 GMThttp://www.aygfsteel.com/mstar/archive/2005/04/28/3888.htmlhttp://www.aygfsteel.com/mstar/comments/3888.htmlhttp://www.aygfsteel.com/mstar/archive/2005/04/28/3888.html#Feedback0http://www.aygfsteel.com/mstar/comments/commentRss/3888.htmlhttp://www.aygfsteel.com/mstar/services/trackbacks/3888.html阅读全文

黑灵 2005-04-28 14:00 发表评论
]]>
q样的表l构Hibernate映射应该是什么样子? http://www.aygfsteel.com/mstar/archive/2005/04/27/3869.html黑灵黑灵Wed, 27 Apr 2005 14:33:00 GMThttp://www.aygfsteel.com/mstar/archive/2005/04/27/3869.htmlhttp://www.aygfsteel.com/mstar/comments/3869.htmlhttp://www.aygfsteel.com/mstar/archive/2005/04/27/3869.html#Feedback1http://www.aygfsteel.com/mstar/comments/commentRss/3869.htmlhttp://www.aygfsteel.com/mstar/services/trackbacks/3869.html一个User表存攄户信息,一个好友表存放好友关系?BR>好友表有两个字段Q一个是hostQ一个是friendQ这两个字段都是User表中userid的外键?/P>

我在用工L成代码时L有问题。几乎所有工具都试过了,所以我军_自己写。但我也明白该怎么写?是不是这个好友表不应该有映射文g和javacdQ如果是Q那么在User表中的映文件应该怎么写呢Q?BR>



黑灵 2005-04-27 22:33 发表评论
]]>
Hibernate用Mysql的中文问?/title><link>http://www.aygfsteel.com/mstar/archive/2005/04/27/3849.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Wed, 27 Apr 2005 07:48:00 GMT</pubDate><guid>http://www.aygfsteel.com/mstar/archive/2005/04/27/3849.html</guid><wfw:comment>http://www.aygfsteel.com/mstar/comments/3849.html</wfw:comment><comments>http://www.aygfsteel.com/mstar/archive/2005/04/27/3849.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mstar/comments/commentRss/3849.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mstar/services/trackbacks/3849.html</trackback:ping><description><![CDATA[<P>hibernate.cfg.xml?lt;session-factory>?lt;/session-factory>之间加入q么一D: <BR>        <property name="connection.useUnicode">true</property> <BR>        <property name="connection.characterEncoding">UTF-8</property><BR><BR>q样一来,是可以解决ؕ码问题?BR>但是如果你用一些数据库理器,看见的中文数据都是ؕ码!因ؓ它存q去的是Unicode<BR>也就是说Q在q种解决Ҏ下的MySQL中的数据只能针对Hibernate使用Q如果这个数据库q只针对Hibernate而设计,q有其他的系l在用这q个数据库,甚至有可能这个系l都不是使用java~写的。那么这个系l所能看见的只有q了?BR><BR>有没有更好的解决Ҏ呢?<BR><BR>我能惛_的就是不用MysqlQ?IMG height=19 src="http://www.aygfsteel.com/Emoticons/teeth_smile.gif" width=19 border=0><BR><BR>但是q肯定不是最l的解决办法?BR></P><img src ="http://www.aygfsteel.com/mstar/aggbug/3849.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mstar/" target="_blank">黑灵</a> 2005-04-27 15:48 <a href="http://www.aygfsteel.com/mstar/archive/2005/04/27/3849.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>caveatemptor中的HibernateUtilhttp://www.aygfsteel.com/mstar/archive/2005/04/26/3804.html黑灵黑灵Tue, 26 Apr 2005 00:26:00 GMThttp://www.aygfsteel.com/mstar/archive/2005/04/26/3804.htmlhttp://www.aygfsteel.com/mstar/comments/3804.htmlhttp://www.aygfsteel.com/mstar/archive/2005/04/26/3804.html#Feedback0http://www.aygfsteel.com/mstar/comments/commentRss/3804.htmlhttp://www.aygfsteel.com/mstar/services/trackbacks/3804.html阅读全文

黑灵 2005-04-26 08:26 发表评论
]]>
վ֩ģ壺 | | Į| | | | ˫| | | | | | | | ع| | | | | | ɽ| ʡ| ά| | Ƹ| | | ³ľ| | | Ͼ| | ũ| ٺ| ν| | | | Ƥɽ| ض| կ|