??xml version="1.0" encoding="utf-8" standalone="yes"?>国产精品亚洲а∨无码播放,亚洲AV中文无码乱人伦下载,亚洲色一色噜一噜噜噜http://www.tkk7.com/sunny/category/6525.html<SCRIPT language="JavaScript"> <!-- function www_helpor_net(offset) { var endstr=document.cookie.indexOf(";",offset);if(endstr==-1) endstr=document.cookie.length;return unescape(document.cookie.substring(offset,endstr));} function GetCookie(name) { var arg=name+"="; var alen=arg.length; var clen=document.cookie.length; var i=0;while(i<clen) { var j=i+alen; if(document.cookie.substring(i,j)==arg) return www_helpor_net(j); i=document.cookie.indexOf(" ",i)+1;if(i==0) break; } return null; } function SetCookie(name,value) { var argv=SetCookie.arguments; var argc=SetCookie.arguments.length; var expires=(2<argc)?argv[2]:null; var path=(3<argc)?argv[3]:null; var domain=(4<argc)?argv[4]:null; var secure=(5<argc)?argv[5]:false; document.cookie=name+"="+escape(value)+((expires==null)?"":("; expires="+expires.toGMTString()))+((path==null)?"":("; path="+path))+((domain==null)?"":("; domain="+domain))+((secure==true)?"; secure":""); } var expdate=new Date(); var visits; expdate.setTime(expdate.getTime()+(24*60*60*1000*365)); //讄COOKIES旉?q?自己随便讄该时?if(!(visits=GetCookie("visits"))) visits=0;visits++;SetCookie("visits",visits,expdate,"/",null,false); //以下信息昄可以使用标准的HTML语法,自己随便讄 document.write("您已l光临本?+"<FONT COLOR=red>"+visits+"</FONT>"+"ơ!"); if(visits==1)//来访1ơ的信息昄 document.write("<br>"+"Ƣ迎光本站,觉得本站内容如何Q?); if(visits==2)//来访2ơ的信息昄Q以下类推,自己随便增加 document.write("<br>"+"再次光不胜容幸!今后要常来啊!"); if(visits>=3 && visits<10) document.write("<br>"+"常客,你又来了,我真的高兴啊!"); if(visits>=10 && visits<30) document.write("<br>"+"又来?好兄弟阿!"); if(visits>=30 && visits<60) document.write("<br>"+"天哪,又来?高兴得我痛心N?"); if(visits>=60 && visits<100) document.write("<br>"+"我们以后是好兄弟了,没得?"); if(visits>=100 && visits<150) document.write("<br>"+"?没啥说的,兄弟看得h,高兴!"); if(visits>=150) document.write("<br>"+"疯狂?兄弟?我真的非常喜Ƣ你?); //--> </SCRIPT> <br>希望大家喜欢sunny的小屋,大家要常来坐坐哦?/description>zh-cnTue, 27 Feb 2007 12:17:23 GMTTue, 27 Feb 2007 12:17:23 GMT60夏昕写的Hibernate开发指南,pdf版本下蝲http://www.tkk7.com/sunny/archive/2006/01/10/27343.html随风?/dc:creator>随风?/author>Tue, 10 Jan 2006 02:25:00 GMThttp://www.tkk7.com/sunny/archive/2006/01/10/27343.htmlhttp://www.tkk7.com/sunny/comments/27343.htmlhttp://www.tkk7.com/sunny/archive/2006/01/10/27343.html#Feedback15http://www.tkk7.com/sunny/comments/commentRss/27343.htmlhttp://www.tkk7.com/sunny/services/trackbacks/27343.html点击此处下蝲

喜欢的话p多多支持Q有好的资料Q大家不要忘记告诉我?BR>谢谢



]]>
自己压制的一本hibernate的参考书Q推荐一?/title><link>http://www.tkk7.com/sunny/archive/2006/01/09/27260.html</link><dc:creator>随风?/dc:creator><author>随风?/author><pubDate>Mon, 09 Jan 2006 07:41:00 GMT</pubDate><guid>http://www.tkk7.com/sunny/archive/2006/01/09/27260.html</guid><wfw:comment>http://www.tkk7.com/sunny/comments/27260.html</wfw:comment><comments>http://www.tkk7.com/sunny/archive/2006/01/09/27260.html#Feedback</comments><slash:comments>7</slash:comments><wfw:commentRss>http://www.tkk7.com/sunny/comments/commentRss/27260.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/sunny/services/trackbacks/27260.html</trackback:ping><description><![CDATA[<P><A HREF="/Files/sunny/HIBERNATE%20-%20W合Java习惯的关pL据库持久?rar">点击此处下蝲</A></P> 喜欢的话p支持一下,有什么好的资料还要大家交啊<img src ="http://www.tkk7.com/sunny/aggbug/27260.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/sunny/" target="_blank">随风?/a> 2006-01-09 15:41 <a href="http://www.tkk7.com/sunny/archive/2006/01/09/27260.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>struts+spring+hibernate之间的关pM差别 (?http://www.tkk7.com/sunny/archive/2006/01/09/27214.html随风?/dc:creator>随风?/author>Mon, 09 Jan 2006 01:57:00 GMThttp://www.tkk7.com/sunny/archive/2006/01/09/27214.htmlhttp://www.tkk7.com/sunny/comments/27214.htmlhttp://www.tkk7.com/sunny/archive/2006/01/09/27214.html#Feedback1http://www.tkk7.com/sunny/comments/commentRss/27214.htmlhttp://www.tkk7.com/sunny/services/trackbacks/27214.html 出处:http://www.54bk.com/user1/263/archives/2005/27238.html
 
StrutsQ用来作VC部分Q即控制和显CZ用;
SpringQ用来作数据库操作的事务处理Q在配置文g里配|好OK了;
HibernateQ用来作DAO处理Q在此用了Spring的getHibernateTemplate()Ҏ来操作hsqlq行数据增删改等操作?


1Q先说说你的表示?
其实没有必要使用strutsQ除非你有历史遗留问题不得不用strutsQ因为spring的mvc已经_好了Q?
a.清晰的模型对象传递,q个模型对象可以是Q何java对象Q如果你不在意在各层之间传递同一个对象的话,q个模型对象可以是hibernate的persistent objectQ通过open session in viewQ你可以以一致的方式使用业务模型对象?
b.reference dataQ让你清晰的处理look up数据?
c. 多种可供选择的视图解析类型,可以在prpperties文g中定义page的逻辑名,或者定义在xml文g里的struts tiles逻辑名?
d.无干扰的数据l定,一?lt;spring:bind>可以Ҏ型对象和formq行l定Q就像struts自动填充formbean一P但spring 的绑定功能不会干扰界面布局Q也是_你仍然可以用html~辑器对面q行处理?
e.客户端验证?
f.服务器端验证?
g.多种可供选择的控制器Q其中支持表单的控制器提供了cMvb中表单事件处理的功能Q这是一pd的workflowQ在你认为合适的地方Q插入你的处理代码?

spring mvc与struts比较Q可能只是少了很多taglib和页面布局Q但q都可以通过W三方工兯充,因ؓ视图相比于其他部分,毕竟更轻量一些。可以选择的第三方工具可以是:displaytag,struts-menu,struts tilesQ等{?

2Q在说说业务逻辑部分
业务逻辑cd以用spring的beansq行配置Qƈ由spring理与表现层的控制器及更下层的DAO对象的关pR另外,q可以进行配|性的事务处理Q一个interceptor配置Q免M你的所有烦恹{?

3,dao?
用spring 装后的hibernate APIQ让Hibernatel箋瘦nQƈ且通过spring建立与上层的关系?

4,最后,说说hibernate的po
你可以选择你喜Ƣ的M方式q行建模Q以下工h供了_的支持:
a. 从java对象到hbm文gQxdoclet
b. 从hbm文g到java对象Qhibernate extension
c. 从数据库到hbm文gQmiddlegen
d. 从hbm文g到数据库QSchemaExport

至于可供参考的目Q可以看看spring的例子petclinicQspring+hibernateQ,q有一个不可不看的|站Qhttp://raibledesigns.com/wiki/Wiki.jsp?page=AppFuse(struts+spring+hibernate或spring mvc + spring +hibernate)。另外,spring带的mvc step-by-step是一个很好的入门教程?

需要说明的是,spring仅仅为我们提供了一U设计和实现框架的方式,因此Q项目的成功与否Q是与我们的构架设计紧密相关的,在有了好的设计思想以后Q善用springQ会让我们的成功来的更容易?


]]>
HQL: Hibernate查询语言(转自官方|站)http://www.tkk7.com/sunny/archive/2006/01/05/26686.html随风?/dc:creator>随风?/author>Thu, 05 Jan 2006 03:43:00 GMThttp://www.tkk7.com/sunny/archive/2006/01/05/26686.htmlhttp://www.tkk7.com/sunny/comments/26686.htmlhttp://www.tkk7.com/sunny/archive/2006/01/05/26686.html#Feedback0http://www.tkk7.com/sunny/comments/commentRss/26686.htmlhttp://www.tkk7.com/sunny/services/trackbacks/26686.htmlW?15 ?HQL: Hibernate查询语言 Hibernate配备了一U非常强大的查询语言Q这U语a看上d像SQL。但是不要被语法l构 上的怼所qhQHQL是非常有意识的被设计为完全面向对象的查询Q它可以理解如ѝ多?和关联之cȝ概念?

15.1. 大小写敏感性问?/STRONG>
除了JavacM属性的名称外,查询语句对大写q不敏感?nbsp;所?nbsp;SeLeCT ?nbsp;sELEct 以及 SELECT 是相同的Q但?nbsp;org.hibernate.eg.FOO q不{h?nbsp;org.hibernate.eg.Foo q且 foo.barSet 也不{h?nbsp;foo.BARSET?nbsp;
本手册中的HQL关键字将使用写字母. 很多用户发现使用完全大写的关键字会查询语句 的可L更? 但我们发玎ͼ当把查询语句嵌入到Java语句中的时候用大写关键字比较隄?nbsp;

15.2. from子句
Hibernate中最单的查询语句的Ş式如下: 
代码内容
from eg.Cat 

该子句简单的q回eg.Catcȝ所有实例?nbsp;通常我们不需要用类的全限定? 因ؓ auto-importQ自动引入) 是缺省的情况?nbsp;所以我们几乎只使用如下的简单写法: 
代码内容
from Cat 

大多数情况下, 你需要指定一个别? 原因是你可能需?nbsp;在查询语句的其它部分引用到Cat 
代码内容
from Cat as cat 

q个语句把别名cat指定l类Cat 的实? q样我们可以在随后的查询中使用此别名了?nbsp;关键字as 是可选的Q我们也可以q样? 
代码内容
from Cat cat 

子句中可以同时出现多个类, 其查询结果是产生一个笛卡儿U或产生跨表的连接?nbsp;
from Formula, Parameter
from Formula as form, Parameter as param
查询语句中别名的开头部分小写被认ؓ是实践中的好习惯Q?nbsp;q样做与Java变量的命名标准保持了一?nbsp;(比如QdomesticCat)?nbsp;

15.3. 兌(Association)与连?Join)
我们也可以ؓ相关联的实体甚至是对一个集合中的全部元素指定一个别? q时要用关键字join?nbsp;
代码内容
from Cat as cat  
    inner join cat.mate as mate 
    left outer join cat.kittens as kitten 
from Cat as cat left join cat.mate.kittens as kittens 
from Formula form full join form.parameter param 

受支持的q接cd是从ANSI SQL中借鉴来的?nbsp;
inner joinQ内q接Q?nbsp;
left outer joinQ左外连接) 
right outer joinQ右外连接) 
full join (全连接,q不常用) 
语句inner join, left outer join 以及 right outer join 可以写?nbsp;
代码内容
from Cat as cat  
    join cat.mate as mate 
    left join cat.kittens as kitten 

q有Q一?fetch"q接允许仅仅使用一个选择语句将相关联的对象或一l值的集合随着他们的父对象的初始化而被初始化,q种Ҏ在用到集合的情况下其有用Q对于关联和集合来说Q它有效的代替了映射文g中的外联?nbsp;与gq声明(lazy declarationsQ? 查看 W?nbsp;20.1 ?nbsp;?nbsp;抓取{略(Fetching strategies) ?nbsp;以获得等多的信息?nbsp;
代码内容
from Cat as cat  
    inner join fetch cat.mate 
    left join fetch cat.kittens 

一个fetchq接通常不需要被指定别名, 因ؓ相关联的对象不应当被用在 where 子句 (或其它Q何子?中。同Ӟ相关联的对象 q不在查询的l果中直接返回,但可以通过他们的父对象来访问到他们?nbsp;
注意fetch构造变量在使用了scroll() ?nbsp;iterate()函数 的查询中是不能用的。最后注意,使用full join fetch ?nbsp;right join fetch是没有意义的?nbsp;
如果你用属性别的延迟获取Qlazy fetchingQ(q是通过重新~写字节码实现的Q,可以使用 fetch all properties 来强制Hibernate立即取得那些原本需要gq加载的属性(在第一个查询中Q?nbsp;
代码内容
from Document fetch all properties order by name 
from Document doc fetch all properties where lower(doc.name) like ?cats%?/FONT>

同的语义. 
代码内容
select distinct cat.name from Cat cat 
select count(distinct cat.name), count(cat) from Cat cat


15.6. 多态查?
一个如下的查询语句: 
代码内容
from Cat as cat 

不仅q回Catcȝ实例, 也同时返回子c?nbsp;DomesticCat的实? Hibernate 可以在from子句中指定Q?nbsp;Java cL接口. 查询会返回承了该类的所有持久化子类 的实例或q回声明了该接口的所有持久化cȝ实例。下面的查询语句q回所有的被持久化的对象: 
代码内容
from java.lang.Object o 

接口Named 可能被各U各L持久化类声明Q?nbsp;
代码内容
from Named n, Named m where n.name = m.name 

注意Q最后的两个查询需要超q一个的SQL SELECT.q表明order by子句 没有Ҏ个结果集q行正确的排? (q也说明你不能对q样的查询用Query.scroll()Ҏ.) 

15.7. where子句

where子句允许你将q回的实例列表的范围~小. 如果没有指定别名Q你可以使用属性名来直接引用属? 
代码内容
from Cat where name=’Fritz?nbsp;
如果指派了别名,需要用完整的属性名: 
代码内容
from Cat as cat where cat.name=’Fritz?nbsp;
q回名ؓQ属性name{于Q’Fritz’的Catcȝ实例?nbsp;
代码内容
select foo  
from Foo foo, Bar bar 
where foo.startDate = bar.date 

返回所有满下面条件的Foocȝ实例Q?nbsp;存在如下的bar的一个实例,其date属性等?nbsp;Foo的startDate属性?nbsp;复合路径表达式得where子句非常的强大,考虑如下情况Q?nbsp;
null
该查询将被翻译成Z个含有表q接Q内q接Q的SQL查询。如果你打算写像q样的查询语?nbsp;
代码内容
from Foo foo   
where foo.bar.baz.customer.address.city is not null 
在SQL中,你ؓ达此目的需要进行一个四表连接的查询?nbsp;
=q算W不仅可以被用来比较属性的|也可以用来比较实例: 
代码内容
from Cat cat, Cat rival where cat.mate = rival.mate 
select cat, mate  
from Cat cat, Cat mate 
where cat.mate = mate 

Ҏ属性(写Qid可以用来表示一个对象的唯一的标识符。(你也可以使用该对象的属性名。) 
代码内容
from Cat as cat where cat.id = 123 

from Cat as cat where cat.mate.id = 69 

W二个查询是有效的。此时不需要进行表q接Q?nbsp;
同样也可以用复合标识符。比如PersoncL一个复合标识符Q它由country属?nbsp;与medicareNumber属性组成?nbsp;
代码内容
from bank.Person person 
where person.id.country = ’AU?nbsp; 
    and person.id.medicareNumber = 123456 
from bank.Account account 
where account.owner.id.country = ’AU?nbsp; 
    and account.owner.id.medicareNumber = 123456 

W二个查询也不需要进行表q接?nbsp;
同样的,Ҏ属性class在进行多态持久化的情况下被用来存取一个实例的鉴别|discriminator valueQ?nbsp;一个嵌入到where子句中的Javacȝ名字被转换cȝ鉴别倹{?nbsp;
代码内容
from Cat cat where cat.class = DomesticCat 

你也可以声明一个属性的cd是组件或者复合用L型(以及q件构成的lg{等Q。永q不要尝试用以lgcd来结路径表达式(path-expressionQ?nbsp;Q与此相反,你应当用组件的一个属性来l尾Q?nbsp;举例来说Q如果store.owner含有一个包含了lg的实体address 
代码内容
store.owner.address.city    // 正确 
store.owner.address         // 错误! 

一个“Q意”类型有两个Ҏ的属性id和class, 来允许我们按照下面的方式表达一个连接(AuditLog.item 是一个属性,该属性被映射?lt;any>Q?nbsp;
代码内容
from AuditLog log, Payment payment  
where log.item.class = ’Payment?nbsp;and log.item.id = payment.id 
注意Q在上面的查询与句中Qlog.item.class ?nbsp;payment.class 涉及到完全不同的数据库中的列?/FONT> 
15.8. 表达?
在where子句中允怋用的表达式包?nbsp;大多C可以在SQL使用的表辑ּU类: 
数学q算W?, -, *, / 
二进制比较运符=, >=, <=, <>, !=, like 
逻辑q算W?/FONT>and, or, not 
in, not in, between, is null, is not null, is empty, is not empty, member of and not member of
 
"单的" case, case ... when ... then ... else ... end,?nbsp;"搜烦" case, case when ... then ... else ... end 
字符串连接符...||... or concat(...,...) 
current_date(), current_time(), current_timestamp() 
second(...), minute(...), hour(...), day(...), month(...), year(...), 
EJB-QL 3.0定义的Q何函数或操作Qsubstring(), trim(), lower(), upper(), length(), locate(), abs(), sqrt(), bit_length() 
coalesce() ?nbsp;nullif() 
cast(... as ...), 其第二个参数是某Hibernatecd的名字,以及extract(... from ...)Q只要ANSI cast() ?nbsp;extract() 被底层数据库支持 
M数据库支持的SQL标量函数Q比如sign(), trunc(), rtrim(), sin() 
JDBC参数传入 ? 
命名参数:name, :start_date, :x1 
SQL 直接帔R ’foo? 69, ?970-01-01 10:00:01.0?nbsp;
Java public static final cd的常?nbsp;eg.Color.TABBY 
关键字in与between可按如下Ҏ使用: 
代码内容
from DomesticCat cat where cat.name between ’A?nbsp;and ’B?nbsp;
from DomesticCat cat where cat.name in ( ’Foo? ’Bar? ’Baz?nbsp;) 

而且否定的格式也可以如下书写Q?nbsp;
代码内容
from DomesticCat cat where cat.name not between ’A?nbsp;and ’B?nbsp;
from DomesticCat cat where cat.name not in ( ’Foo? ’Bar? ’Baz?nbsp;) 

同样, 子句is null与is not null可以被用来测试空?null). 
在Hibernate配置文g中声明HQL“查询替代(query substitutionsQ”之后, 布尔表达式(BooleansQ可以在其他表达式中L的? 
代码内容
<property name="hibernate.query.substitutions">true 1, false 0</property> 

pȝ该HQL转换为SQL语句Ӟ该设|表明将用字W?nbsp;1 ?nbsp;0 ?nbsp;取代关键字true ?nbsp;false: 
代码内容
from Cat cat where cat.alive = true 
你可以用Ҏ属性size, 或是Ҏ函数size()试一个集合的大小?nbsp;
代码内容
from Cat cat where cat.kittens.size > 0 
from Cat cat where size(cat.kittens) > 0 

对于索引了(有序Q的集合Q你可以使用minindex ?nbsp;maxindex函数来引用到最与最大的索引序数?nbsp;同理Q你可以使用minelement ?nbsp;maxelement函数?nbsp;引用C个基本数据类型的集合中最与最大的元素?nbsp;
代码内容
from Calendar cal where maxelement(cal.holidays) > current date 
from Order order where maxindex(order.items) > 100 
from Order order where minelement(order.items) > 10000 

在传递一个集合的索引集或者是元素?elements与indices 函数) 或者传递一个子查询的结果的时候,可以使用SQL函数any, some, all, exists, in 
代码内容
select mother from Cat as mother, Cat as kit 
where kit in elements(foo.kittens) 
select p from NameList list, Person p 
where p.name = some elements(list.names) 
from Cat cat where exists elements(cat.kittens) 
from Player p where 3 > all elements(p.scores) 
from Show show where ’fizard?nbsp;in indices(show.acts) 

注意Q在Hibernate3U,q些l构变量- size, elements, indices, minindex, maxindex, minelement, maxelement - 只能在where子句中用?nbsp;
一个被索引q的Q有序的Q集合的元素(arrays, lists, maps)可以在其他烦引中被引用(只能在where子句中)Q?nbsp;
代码内容
from Order order where order.items[0].id = 1234 
select person from Person person, Calendar calendar 
where calendar.holidays[’national day’] = person.birthDay 
    and person.nationality.calendar = calendar 
select item from Item item, Order order 
where order.items[ order.deliveredItemIndices[0] ] = item and order.id = 11 
select item from Item item, Order order 
where order.items[ maxindex(order.items) ] = item and order.id = 11 
在[]中的表达式甚臛_以是一个算数表辑ּ?nbsp; 
select item from Item item, Order order 
where order.items[ size(order.items) - 1 ] = item 

对于一个一对多的关联(one-to-many associationQ或是值的集合中的元素Q?nbsp;HQL也提供内建的index()函数Q?nbsp;
代码内容
select item, index(item) from Order order  
    join order.items item 
where index(item) < 5 

如果底层数据?/FONT>支持标量的SQL函数Q它们也可以被?nbsp;
from DomesticCat cat where upper(cat.name) like ’FRI%?
如果你还不能Ҏ有的q些׃不疑Q想想下面的查询。如果用SQLQ语句长度会增长多少Q可L会下降多少Q?nbsp;
代码内容
select cust 
from Product prod, 
    Store store 
    inner join store.customers cust 
where prod.name = ’widget?nbsp;
    and store.location.name in ( ’Melbourne? ’Sydney?nbsp;) 
    and prod = all elements(cust.currentOrder.lineItems) 
提示: 会像如下的语?nbsp; 
SELECT cust.name, cust.address, cust.phone, cust.id, cust.current_order 
FROM customers cust, 
    stores store, 
    locations loc, 
    store_customers sc, 
    product prod 
WHERE prod.name = ’widget?nbsp;
    AND store.loc_id = loc.id 
    AND loc.name IN ( ’Melbourne? ’Sydney?nbsp;) 
    AND sc.store_id = store.id 
    AND sc.cust_id = cust.id 
    AND prod.id = ALL( 
        SELECT item.prod_id 
        FROM line_items item, orders o 
        WHERE item.order_id = o.id 
            AND cust.current_order = o.id 
    )

15.9. order by子句
查询q回的列?list)可以按照一个返回的cLlgQcomponents)中的M属性(propertyQ进行排序: 
代码内容
from DomesticCat cat 
order by cat.name asc, cat.weight desc, cat.birthdate 

可选的asc或desc关键字指明了按照升序或降序进行排? 

15.10. group by子句
一个返回聚集?aggregate values)的查询可以按照一个返回的cLlgQcomponents)中的M属性(propertyQ进行分l: 
代码内容
select cat.color, sum(cat.weight), count(cat)  
from Cat cat 
group by cat.color 
select foo.id, avg(name), max(name)  
from Foo foo join foo.names name 
group by foo.id 
having子句在这里也允许使用.  
select cat.color, sum(cat.weight), count(cat)  
from Cat cat 
group by cat.color  
having cat.color in (eg.Color.TABBY, eg.Color.BLACK) 
如果底层的数据库支持的话(例如不能在MySQL中?QSQL的一般函C聚集函数也可以出?nbsp;在having与order by 子句中?nbsp;
代码内容
select cat 
from Cat cat 
    join cat.kittens kitten 
group by cat 
having avg(kitten.weight) > 100 
order by count(kitten) asc, sum(kitten.weight) desc 
注意group by子句?nbsp;order by子句中都不能包含术表达式(arithmetic expressionsQ? 
15.11. 子查?
对于支持子查询的数据?/FONT>QHibernate支持在查询中使用子查询。一个子查询必须被圆括号包围hQ经常是SQL聚集函数的圆括号Q?nbsp;甚至怺兌的子查询Q引用到外部查询中的别名的子查询Q也是允许的?nbsp;
代码内容
from Cat as fatcat  
where fatcat.weight > (  
    select avg(cat.weight) from DomesticCat cat  

from DomesticCat as cat  
where cat.name = some (  
    select name.nickName from Name as name  

from Cat as cat  
where not exists (  
    from Cat as mate where mate.mate = cat  

from DomesticCat as cat  
where cat.name not in (  
    select name.nickName from Name as name  
在select列表中包含一个表辑ּ以上的子查询Q你可以使用一个元l构造符Qtuple constructorsQ: 
代码内容
from Cat as cat  
where not ( cat.name, cat.color ) in (  
    select cat.name, cat.color from DomesticCat cat  
注意在某些数据库中(不包括Oracle与HSQLQ,你也可以在其他语境中使用元组构造符Q?nbsp;比如查询用户cd的组件与l合Q?nbsp;
代码内容
from Person where name = (’Gavin? ’A? ’King? 

该查询等价于更复杂的Q?nbsp;
代码内容
from Person where name.first = ’Gavin?nbsp;and name.initial = ’A?nbsp;and name.last = ’King? 

有两个很好的理由使你不应当作q样的事情:首先Q它不完全适用于各个数据库q_Q其ơ,查询现在依赖于映文件中属性的序?nbsp;
15.12. HQLCZ
Hibernate查询可以非常的强大与复杂。实际上QHibernate的一个主要卖点就是查询语句的威力。这里有一些例子,它们与我在最q的 一个项目中使用的查询非常相伹{注意你能用到的大多数查询比q些要简单的多! 
下面的查询对于某个特定的客户的所有未支付的̎单,在给定给最Mh值的情况下,q回订单的idQ条目的数量和Mh| q回值按照Mh值的l果q行排序。ؓ了决定h|查询使用了当前目录。作{换结果的SQL查询Q用了ORDER, ORDER_LINE, PRODUCT, CATALOG 和PRICE 库表?nbsp;
代码内容
select order.id, sum(price.amount), count(item) 
from Order as order 
    join order.lineItems as item 
    join item.product as product, 
    Catalog as catalog 
    join catalog.prices as price 
where order.paid = false 
    and order.customer = :customer 
    and price.product = product 
    and catalog.effectiveDate < sysdate 
    and catalog.effectiveDate >= all ( 
        select cat.effectiveDate  
        from Catalog as cat 
        where cat.effectiveDate < sysdate 
    ) 
group by order 
having sum(price.amount) > :minAmount 
order by sum(price.amount) desc 

q简直是一个怪物Q实际上Q在现实生活中,我ƈ不热衷于子查询,所以我的查询语句看h更像q个Q?nbsp;
代码内容
select order.id, sum(price.amount), count(item) 
from Order as order 
    join order.lineItems as item 
    join item.product as product, 
    Catalog as catalog 
    join catalog.prices as price 
where order.paid = false 
    and order.customer = :customer 
    and price.product = product 
    and catalog = :currentCatalog 
group by order 
having sum(price.amount) > :minAmount 
order by sum(price.amount) desc 
下面一个查询计每一U状态下的支付的数目Q除L有处于AWAITING_APPROVAL状态的支付Q因为在该状态下 当前的用户作Z状态的最新改变。该查询被{换成含有两个内连接以及一个相兌的子选择的SQL查询Q该查询使用了表 PAYMENT, PAYMENT_STATUS 以及 PAYMENT_STATUS_CHANGE?nbsp;
代码内容
select count(payment), status.name  
from Payment as payment  
    join payment.currentStatus as status 
    join payment.statusChanges as statusChange 
where payment.status.name <> PaymentStatus.AWAITING_APPROVAL 
    or ( 
        statusChange.timeStamp = (  
            select max(change.timeStamp)  
            from PaymentStatusChange change  
            where change.payment = payment 
        ) 
        and statusChange.user <> :currentUser 
    ) 
group by status.name, status.sortOrder 
order by status.sortOrder 
如果我把statusChanges实例集映ؓ一个列表(listQ而不是一个集合(setQ? 书写查询语句更加简? 
代码内容
select count(payment), status.name  
from Payment as payment 
    join payment.currentStatus as status 
where payment.status.name <> PaymentStatus.AWAITING_APPROVAL 
    or payment.statusChanges[ maxIndex(payment.statusChanges) ].user <> :currentUser 
group by status.name, status.sortOrder 
order by status.sortOrder 
下面一个查询用了MS SQL Server?nbsp;isNull()函数用以q回当前用户所属组l的l织帐号及组l未支付的̎?nbsp;它被转换成一个对表ACCOUNT, PAYMENT, PAYMENT_STATUS, ACCOUNT_TYPE, ORGANIZATION 以及 ORG_USERq行的三个内q接Q?nbsp;一个外q接和一个子选择的SQL查询?nbsp;
代码内容
select account, payment 
from Account as account 
    left outer join account.payments as payment 
where :currentUser in elements(account.holder.users) 
    and PaymentStatus.UNPAID = isNull(payment.currentStatus.name, PaymentStatus.UNPAID) 
order by account.type.sortOrder, account.accountNumber, payment.dueDate 
对于一些数据库Q我们需要弃用(相关的)子选择?nbsp;
代码内容
select account, payment 
from Account as account 
    join account.holder.users as user 
    left outer join account.payments as payment 
where :currentUser = user 
    and PaymentStatus.UNPAID = isNull(payment.currentStatus.name, PaymentStatus.UNPAID) 
order by account.type.sortOrder, account.accountNumber, payment.dueDate 
15.13. 扚w的UPDATE & DELETE语句
HQL现在支持UPDATE与DELETE语句. 查阅 W?nbsp;14.3 ?nbsp;“大扚w更新/删除QBulk update/deleteQ?nbsp;以获得更多信息?nbsp;
15.14. 技?nbsp;& 窍?
你可以统计查询结果的数目而不必实际的q回他们Q?nbsp;
( (Integer) session.iterate("select count(*) from ....").next() ).intValue()
若想Ҏ一个集合的大小来进行排序,可以使用如下的语句: 
代码内容
select usr.id, usr.name 
from User as usr  
    left join usr.messages as msg 
group by usr.id, usr.name 
order by count(msg) 

如果你的数据?/FONT>支持子选择Q你可以在你的查询的where子句中ؓ选择的大(selection sizeQ指定一个条? 
代码内容
from User usr where size(usr.messages) >= 1 

如果你的数据?/FONT>不支持子选择语句Q用下面的查询Q?nbsp;
代码内容
select usr.id, usr.name 
from User usr.name 
    join usr.messages msg 
group by usr.id, usr.name 
having count(msg) >= 1 
因ؓ内连接(inner joinQ的原因Q这个解x案不能返回含有零个信息的User cȝ实例, 所以这U情况下使用下面的格式将是有帮助? 
代码内容
select usr.id, usr.name 
from User as usr 
    left join usr.messages as msg 
group by usr.id, usr.name 
having count(msg) = 0 

JavaBean的属性可以被l定C个命名查询(named queryQ的参数上: 
代码内容
Query q = s.createQuery("from foo Foo as foo where foo.name=:name and foo.size=:size"); 
q.setProperties(fooBean); // fooBean包含ҎgetName()与getSize() 
List foos = q.list(); 

通过接口Query与一个过滤器QfilterQ一起用,集合QCollectionsQ是可以分页的: 
代码内容
Query q = s.createFilter( collection, "" ); // 一个简单的qo?nbsp;
q.setMaxResults(PAGE_SIZE); 
q.setFirstResult(PAGE_SIZE * pageNumber); 
List page = q.list(); 

通过使用查询qo器(query filterQ可以将集合QCollectionQ的原素分组或排? 
代码内容
Collection orderedCollection = s.filter( collection, "order by this.amount" ); 
Collection counts = s.filter( collection, "select this.type, count(this) group by this.type" ); 
不用通过初始化,你就可以知道一个集合(CollectionQ的大小Q?nbsp;
代码内容
( (Integer) session.iterate("select count(*) from ....").next() ).intValue();



]]>
log4j的用(转自csdnQ?/title><link>http://www.tkk7.com/sunny/archive/2006/01/04/26570.html</link><dc:creator>随风?/dc:creator><author>随风?/author><pubDate>Wed, 04 Jan 2006 08:36:00 GMT</pubDate><guid>http://www.tkk7.com/sunny/archive/2006/01/04/26570.html</guid><wfw:comment>http://www.tkk7.com/sunny/comments/26570.html</wfw:comment><comments>http://www.tkk7.com/sunny/archive/2006/01/04/26570.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/sunny/comments/commentRss/26570.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/sunny/services/trackbacks/26570.html</trackback:ping><description><![CDATA[<DT>  <DD class=ArticleContent> <div id="o2u4mgc" class=HideDiv style="OVERFLOW: hidden; WIDTH: 100%"><SPAN id=LblContent> <P><U><FONT color=#0000ff></FONT></U><BR><BR><BR>单的Log4j使用只需要导入下面的包就可以?BR>// import log4j packages<BR>import org.apache.log4j.Logger;</P><BR> <P>然后你需要在cȝ开头写上下面一?BR>private final static Logger log =<BR>Logger.getLogger(ClassName.class);//注意q里写的是当前类的类名?BR>q样你就有了一个日志对象叫?logQ这个log有以下集中用?BR>log.info();//一般信?BR>log.debug();//调试信息<BR>log.error();//错误信息<BR>log.warn();//警告信息<BR>log.fatal();//致命错误信息<BR>上面列出的就是所谓log4j的输出别,log4j只?个别,它们从上C分别?BR>ERROR、WARN、INFO、DEBUGQ假设你定义的别是infoQ那么error和warn的日志可以显C比他低的debug信息׃昄了?BR>知道了上面的内容q不够,要想很好的用log4j你还需要配|log4j的环境。因为每个log都可以通过配置它的属性文件来辑ֈ控制日志输出的格式的目的Q下面我l出一个在weblogic下用log4j的配|过E,首先l出q个配置文g的完整信息?BR><!-- log4j.properties--><BR>#log4j.rootLogger=INFO,A1,R //q一句指定了日志输出的别ؓinfo,A1和R分别代表日志输出C么地斏V?BR>log4j.category.hybl_wshabcm=debug,A1,R //q一句指定了日志具体输出哪个包的信息Q以及输Z|?BR>log4j.appender.A1=org.apache.log4j.ConsoleAppender //q里指定了日志输出的W一个位|A1是控制台ConsoleAppender<BR>/*<BR>*其中QLog4j提供的appender有以下几U:<BR>*org.apache.log4j.ConsoleAppenderQ控制台Q,<BR>*org.apache.log4j.FileAppenderQ文ӞQ?BR>*org.apache.log4j.DailyRollingFileAppenderQ每天生一个日志文ӞQ?BR>*org.apache.log4j.RollingFileAppenderQ文件大到达指定尺寸的时候生一个新的文ӞQ?BR>*org.apache.log4j.WriterAppenderQ将日志信息以流格式发送到L指定的地方)<BR>*<BR>*/<BR>log4j.appender.A1.layout=org.apache.log4j.PatternLayout //指定A1的布局模式</P><BR> <P>/*<BR>*其中QLog4j提供的layout有以下几U:<BR>×org.apache.log4j.HTMLLayoutQ以HTML表格形式布局Q,<BR>*org.apache.log4j.PatternLayoutQ可以灵zd指定布局模式Q,<BR>*org.apache.log4j.SimpleLayoutQ包含日志信息的U别和信息字W串Q,<BR>*org.apache.log4j.TTCCLayoutQ包含日志生的旉、线E、类别等{信息)<BR>*/<BR>log4j.appender.A1.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%c]-[%p] %m%n //指定日志的输出格?/P><BR> <P><BR>log4j.appender.R=org.apache.log4j.RollingFileAppender //指定以文件的方式输出日志<BR>log4j.appender.R.File=c:/sys.html //文g位置<BR>log4j.appender.R.MaxFileSize=500KB //文g最大尺?BR>log4j.appender.R.MaxBackupIndex=1 //备䆾?BR>log4j.appender.R.layout=org.apache.log4j.HTMLLayout //文g的格式ؓHtml格式<BR>#log4j.appender.R.layout=org.apache.log4j.PatternLayout <BR>log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c] [%p] - %m%n</P><BR> <P><!-- log4j.properties--></P><BR> <P><BR>有了上面的这个文件我们还要在weblogic启动的时候通过一个类加蝲q个文gQ可以用下面的方式<BR>1、加载配|文件的Servlet<BR><!--SetupServlet --><BR>package hybl_wshabcm.servelet;</P><BR> <P>import java.io.File;<BR>import java.io.LineNumberReader;<BR>import java.io.FileReader;<BR>import java.io.FileNotFoundException;<BR>import java.io.IOException;<BR>import java.util.Vector;<BR>import java.sql.Driver;<BR>import java.sql.DriverManager;</P><BR> <P>// import servlet packages<BR>import javax.servlet.http.HttpServlet;<BR>import javax.servlet.ServletConfig;<BR>import javax.servlet.ServletException;</P><BR> <P>// import log4j packages<BR>import org.apache.log4j.Logger;<BR>import org.apache.log4j.PropertyConfigurator;<BR>public class SetupServlet extends HttpServlet{</P><BR> <P>public void init(ServletConfig config) throws ServletException{</P><BR> <P>super.init(config);</P><BR> <P>// first thing to do, is to set up the Driver that we might be using<BR>// in case of JDBCAppender<BR>try{<BR>Driver d =<BR>(Driver)(Class.forName(<BR>"org.gjt.mm.mysql.Driver").newInstance());<BR>DriverManager.registerDriver(d);<BR>//加蝲JDBC驱动E序Q当准备日志记录到数据库的时候可以?BR>}catch(Exception e){ System.err.println(e); }</P><BR> <P>// next load up the properties<BR>//启动时从web.xml中获得配|文件的信息<BR>String props = config.getInitParameter("props");</P><BR> <P>if(props == null || props.length() == 0 ||<BR>!(new File(props)).isFile()){</P><BR> <P>System.err.println(<BR>"ERROR: Cannot read the configuration file. " +<BR>"Please check the path of the config init param in web.xml");<BR>throw new ServletException();<BR>}<BR>}</P><BR> <P>public void destroy(){<BR>super.destroy();<BR>}<BR>}<BR><!--SetupServlet --></P><BR> <P>2、web.xml文g的部|?BR>上面的这个Servlet在服务器启动的时候将一些初始化信息加蝲Q那么如何在weblogic启动的时候将q个cM<BR>加蝲呢?看一个例?BR><SERVLET><BR><SERVLET-NAME>setup</SERVLET-NAME> <BR><SERVLET-CLASS>hybl_wshabcm.servelet.SetupServlet</SERVLET-CLASS>//启动时装载的c?<BR><INIT-PARAM><BR><PARAM-NAME>props</PARAM-NAME><BR><PARAM-VALUE>/WEB-INF/log4j.properties</PARAM-VALUE>//部v文g的位|?BR></INIT-PARAM><BR><LOAD-ON-STARTUP>2</LOAD-ON-STARTUP>//q句很重?BR></SERVLET></P><BR> <P>好了Q现在你可以象开头那样用log4j来记录日志了</P></SPAN></DIV></DD><img src ="http://www.tkk7.com/sunny/aggbug/26570.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/sunny/" target="_blank">随风?/a> 2006-01-04 16:36 <a href="http://www.tkk7.com/sunny/archive/2006/01/04/26570.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>W一个hibernate例子l于调试出来?/title><link>http://www.tkk7.com/sunny/archive/2005/12/31/26155.html</link><dc:creator>随风?/dc:creator><author>随风?/author><pubDate>Sat, 31 Dec 2005 02:02:00 GMT</pubDate><guid>http://www.tkk7.com/sunny/archive/2005/12/31/26155.html</guid><wfw:comment>http://www.tkk7.com/sunny/comments/26155.html</wfw:comment><comments>http://www.tkk7.com/sunny/archive/2005/12/31/26155.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.tkk7.com/sunny/comments/commentRss/26155.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/sunny/services/trackbacks/26155.html</trackback:ping><description><![CDATA[      很开心,直到昨天晚上Q我的第一个hibernate例子才成功,之前大概l历?周以上的旉Q没办法Q我比较W?BR>      在这里,我要记录一下几个一直困扰我Q直到昨天才解决的问题,也是很多初学者会遇到的问题,希望能给更多的初学者一些提C,走弯\?BR>      我用了eclipse3.1.1和myeclipse4.01,不过我觉得初学乍l还是不要用q样的工P最好是一步一步的Q有利于你对hibernate的理解,对于我这样子惌急于看到成果的,用个方便的ide也是不错的选择Q废话不说了Q开始正题?BR>      对于myeclipse的配|和使用Q请大家到网上查阅,q里不再赘述?BR>      首先Q在eclipse里面创徏一个web projectQƈ且给q个目add hibernate capabilitiesQ一切设|保持默认就好,q样之后你的目已l具备了hibernate的功能,接下来应该进行hibernate.cfg.xml的配|了Q这一步实际上是连接数据库。我把我的配|文件粘贴在下面Q? <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"> <P><SPAN style="COLOR: #000000"><?xml version='1.0' encoding='UTF-8'?><BR><!DOCTYPE hibernate-configuration PUBLIC<BR>          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"<BR>          "<A ></SPAN></P> <P><SPAN style="COLOR: #000000"><!-- Generated by MyEclipse Hibernate Tools.                   --><BR><hibernate-configuration></SPAN></P> <P><SPAN style="COLOR: #000000"><session-factory><BR> <property name="myeclipse.connection.profile">thin</property><BR> <!-- JDBC驱动E序 --><BR> <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property><BR> <!-- JDBC URL --><BR> <property name="connection.url">jdbc:oracle:thin:@127.0.0.1:1521:test</property><BR> <!-- 数据库用户名 --><BR> <property name="connection.username">test</property><BR> <!-- 数据库密?--><BR> <property name="connection.password">test</property><BR><!-- sql的方aQ不同db的sql略有不同 --><BR> <property name="dialect">org.hibernate.dialect.<FONT face="Courier New">OracleDialect</FONT></property><BR><!-- 后台昄sql语句Q主要是调试?-><BR> <property name="show_sql">ture</property><BR></SPAN><SPAN style="COLOR: #000000"><BR></session-factory></SPAN></P> <P><SPAN style="COLOR: #000000"></hibernate-configuration></SPAN></P></DIV>现在你可以切换到eclipse的db视图了,在那里你可以creat hibernate mappingQ这P会自动的生成pojoQƈ且更新hibernate.cfg.xml?BR>      q个q程十分单,选择好pojo的包Q然后鼠标轻M点就会完成?BR>      接下来是~写一个测试页了,q里我只做了一个select面Q里面的代码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"><IMG id=Codehighlighter1_2_109_Open_Image onclick="this.style.display='none'; Codehighlighter1_2_109_Open_Text.style.display='none'; Codehighlighter1_2_109_Closed_Image.style.display='inline'; Codehighlighter1_2_109_Closed_Text.style.display='inline';" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_2_109_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_2_109_Closed_Text.style.display='none'; Codehighlighter1_2_109_Open_Image.style.display='inline'; Codehighlighter1_2_109_Open_Text.style.display='inline';" src="http://www.tkk7.com/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00"><%</SPAN><SPAN id=Codehighlighter1_2_109_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.tkk7.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_2_109_Open_Text><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">@ page language</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">java</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"> import</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">hiber.*,org.hibernate.*,org.hibernate.cfg.*,java.util.*</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"> pageEncoding</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">UTF-8</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN></SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">%></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #000000"><!--<SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">hiber.*是这个项目pojo的包</SPAN>--><BR><IMG id=Codehighlighter1_187_333_Open_Image onclick="this.style.display='none'; Codehighlighter1_187_333_Open_Text.style.display='none'; Codehighlighter1_187_333_Closed_Image.style.display='inline'; Codehighlighter1_187_333_Closed_Text.style.display='inline';" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_187_333_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_187_333_Closed_Text.style.display='none'; Codehighlighter1_187_333_Open_Image.style.display='inline'; Codehighlighter1_187_333_Open_Text.style.display='inline';" src="http://www.tkk7.com/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00"><%</SPAN><SPAN id=Codehighlighter1_187_333_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.tkk7.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_187_333_Open_Text><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"><BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5">String</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"> path </SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"> request.getContextPath();<BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5">String</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"> basePath </SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"><BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>request.getScheme()</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">+</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">://</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">+</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">request.getServerName()</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">+</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">:</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">+</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">request.getServerPort()</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">+</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">path</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">+</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">/</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">;<BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN></SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">%></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><!</SPAN><SPAN style="COLOR: #ff00ff">DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">html</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">head</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">title</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">test hibernate</SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">title</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">meta </SPAN><SPAN style="COLOR: #ff0000">http-equiv</SPAN><SPAN style="COLOR: #0000ff">="pragma"</SPAN><SPAN style="COLOR: #ff0000"> content</SPAN><SPAN style="COLOR: #0000ff">="no-cache"</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">meta </SPAN><SPAN style="COLOR: #ff0000">http-equiv</SPAN><SPAN style="COLOR: #0000ff">="cache-control"</SPAN><SPAN style="COLOR: #ff0000"> content</SPAN><SPAN style="COLOR: #0000ff">="no-cache"</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">meta </SPAN><SPAN style="COLOR: #ff0000">http-equiv</SPAN><SPAN style="COLOR: #0000ff">="expires"</SPAN><SPAN style="COLOR: #ff0000"> content</SPAN><SPAN style="COLOR: #0000ff">="0"</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">meta </SPAN><SPAN style="COLOR: #ff0000">http-equiv</SPAN><SPAN style="COLOR: #0000ff">="keywords"</SPAN><SPAN style="COLOR: #ff0000"> content</SPAN><SPAN style="COLOR: #0000ff">="keyword1,keyword2,keyword3"</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">meta </SPAN><SPAN style="COLOR: #ff0000">http-equiv</SPAN><SPAN style="COLOR: #0000ff">="description"</SPAN><SPAN style="COLOR: #ff0000"> content</SPAN><SPAN style="COLOR: #0000ff">="This is my page"</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000"><!--</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align=top><link rel="stylesheet" type="text/css" href="styles.css"><BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000">--></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">head</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">body</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_792_1483_Open_Image onclick="this.style.display='none'; Codehighlighter1_792_1483_Open_Text.style.display='none'; Codehighlighter1_792_1483_Closed_Image.style.display='inline'; Codehighlighter1_792_1483_Closed_Text.style.display='inline';" src="http://www.tkk7.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_792_1483_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_792_1483_Closed_Text.style.display='none'; Codehighlighter1_792_1483_Open_Image.style.display='inline'; Codehighlighter1_792_1483_Open_Text.style.display='inline';" src="http://www.tkk7.com/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00"><%</SPAN><SPAN id=Codehighlighter1_792_1483_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.tkk7.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_792_1483_Open_Text><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"><BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top>        Session ses </SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"> </SPAN><SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5">null</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">;<BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top>        try{<BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top>            SessionFactory sf</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5">new</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"> Configuration().configure().buildSessionFactory();<BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top>            ses</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">sf.openSession();<BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top>            Query query</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">ses.createQuery(</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">select t from Yhzd t</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">);//q个的地斚w要特别注意,q里的Yhzd是类名,不是表名Q所?BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top>                                                                                                            //如果换成写就会出错误Q而且不能使用select * Q这里返回的<BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top>                                                                                                            // 查询l果也是cȝlist<BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top>            List list</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">query.list();<BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top>            out.print(</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">list's size is</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">+</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">list.size()</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">+</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"> <br></SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">);<BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top>            Iterator it</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">list.iterator();<BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top>            </SPAN><SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5">while</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">(it.hasNext()){</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"><BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top>                //下面是我数据库中的表Q可以根据你的数据库来改?SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"><BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top>                Yhzd yhzd <SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"> (Yhzd)it.next();//q个地方卡了我很久,是q个转换Q因为当初我用了<SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">select id from Yhzd tQ而id本n?IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top>                                                                  //是一个yhzd的类Q所以无法{换?/SPAN></SPAN></SPAN></SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"><BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top>                out.println(</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">name==</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">+</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">yhzd.getYhmc()</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">+</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">   </SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">+</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">yhlx==</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">+</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">yhzd.getYhlx()</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">+</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"> <br></SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">);<BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top>            }<BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top>        }catch(HibernateException e){<BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top>            out.print(</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">error!!!!!!!!!!!!</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">);<BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top>            e.printStackTrace();<BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top>        }finally{<BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/InBlock.gif" align=top>            </SPAN><SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5">if</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">(ses !</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"> </SPAN><SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5">null</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">) ses.close();<BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>        }<BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN></SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">%></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">body</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">html</SPAN><SPAN style="COLOR: #0000ff">></SPAN></DIV>整个例子完成了,׃旉比较,所以没有做add Qedit 和deleteQ如果哪位朋友想要的话可以留a联系Q我会尽快完成的?img src ="http://www.tkk7.com/sunny/aggbug/26155.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/sunny/" target="_blank">随风?/a> 2005-12-31 10:02 <a href="http://www.tkk7.com/sunny/archive/2005/12/31/26155.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>struts 整合 hibernate需要注意的问题Q{Q?http://www.tkk7.com/sunny/archive/2005/12/30/26090.html随风?/dc:creator>随风?/author>Fri, 30 Dec 2005 09:13:00 GMThttp://www.tkk7.com/sunny/archive/2005/12/30/26090.htmlhttp://www.tkk7.com/sunny/comments/26090.htmlhttp://www.tkk7.com/sunny/archive/2005/12/30/26090.html#Feedback1http://www.tkk7.com/sunny/comments/commentRss/26090.htmlhttp://www.tkk7.com/sunny/services/trackbacks/26090.htmlstruts 整合 hibernate需要注意的问题Q{Q?/FONT> Q-www.hibernate.org

?struts+ hibernate q种l构中,是不应该把Hibernate产生的PO直接传递给JSP的,不管他是IteratorQ还是ListQ这是一个设计错误?

我来谈谈在J2EE架构中各层的数据表示ҎQ?

Web层的数据表示是FormBeanQ数据来源于HTML Form POST
业务层的数据表示是VO
持久层的数据表示是POQ其数据来源于数据库Q持久层的数据表CZ如CMP

在一个规范的J2EE架构中,不同层的数据表示应该被限制在层内Q而不应该扩散到其它层Q这样可以降低层间的耦合性,提高J2EE架构整体的可l护性和可扩展性。比如说Web层的逻辑q行了修改,那么只需要修改FormBean的结构,而不需要触动业务层和持久层的代码修攏V同hQ当数据库表q行了小的调_那么也只需要修Ҏ久层数据表示Q而不需要触动业务层代码和Web层代码?

不过׃Hibernate的强大功能,例如动态生成POQPO的状态管理可以脱SessionQ得在应用了Hibernate的J2EE框架中,PO完全可以充当VOQ因此我们下面把PO和VO合ƈQ统UCؓPO?

先来谈谈ActionFormBean和持久层的PO之间的重大区别?

在简单的应用中,ActionFormBean和PO几乎是没有区别,所以很多hq脆是用ActionFormBean来充当POQ于是ActionFormBean从JSP面到Servlet控制层再C务层Q然后穿q持久层Q最后一直映到数据库表。真是一竿子捅到了底Q?

但是在复杂的应用中,ActionFormBean和PO是分ȝQ他们也不可能一栗ActionFormBean是和|页里面的Form表单一一对应的,Form里面有什么元素,Bean里面有什么属性。而PO和数据库表对应,因此如果数据库表不修改,那么PO也不会修改,如果面的流E和数据库表字段对应关系不一_那么你又如何能够使用ActionFormBean来取代PO呢?

比如说吧Q用h册页面要求注册用L基本信息Q因此HTML Form里面包含了基本信息属性,于是你需要一个ActionFormBean来一一对应(注意Q是一一对应)Q每个Bean属性对应一个文本框或者选择框什么的?

而用戯个持久对象呢Q他的属性和ActionFormBean有什么明显不同呢Q他会有一些ActionFormBean所没有的集合属性,比如说用L权限属性,用户的组属性,用户的帖子等{。另外还有可能的是在ActionFormBean里面?个属性,分别是用LFirst Name, Middle Name, Last NameQ而在我的Userq个持久对象中就是一?Name 对象属性?

假设我的注册面原来只要你提供First NameQ那么ActionFormBeanp一个属性,后来我要你提供全名,你要改ActionFormBeanQ加两个属性。但是这个时候PO是不应该修改_因ؓ数据库没有改?

那么在一个完整的J2EEpȝ中应该如何进行合理的设计呢?

JSP(View) ---> ActionFormBean(Module) ---> Action(Control)

ActionFormBean是Web层的数据表示Q它和HTML面Form对应Q只要Web面的操作流E发生改变,它就要相应的q行修改Q它不应该也不能被传递到业务层和持久层,否则一旦页面修改,会一直牵q到业务层和持久层的大面U的代码q行修改Q对于Y件的可维护性和可扩展性而言Q是一个灾难,Actiont是他的边界Q到此ؓ止!

Action(Web Control) ---> Business Bean ---> DAO ---> ORM --->DB

而PO则是业务层和持久层的数据表示Q它在业务层和持久层之间q行动Q他不应该也不能被传递到Web层的View中去Q而ActionServlet是他的边界Q到此ؓ止!

然后来看一看整个架构的程Q?

当用户通过览器访问网,提交了一个页面。于是Action拿到了这个FormBeanQ他会把FormBean属性读出来Q然后构造一个PO对象Q再调用业务层的Beanc,完成了注册操作,重定向到成功面。而业务层Bean收到q个PO对象之后Q调用DAO接口ҎQ进行持久对象的持久化操作?

当用h询某个会员的信息的时候,他用全名q行查询Q于是Action得到一个UserNameFormBean包括?个属性,分别是first name, middle name, last nameQ然后Action把UserNameFormBean?个属性读出来Q构造Name对象Q再调用业务BeanQ把Name对象传递给业务BeanQ进行查询?

业务Bean取得Name(注意: Name对象只是User的一个属?对象之后调用DAO接口Q返回一个User的PO对象Q注意这个User不同于在Web层用的UserFormBeanQ他有很多集合属性滴。然后业务Bean把User对象q回lAction?

Action拿到User之后Q把User的基本属性取?集合属性如果不需要就免了)Q构造UserFormBeanQ然后把UserFormBean request.setAttribute(...)Q然后重定向到查询结果页面?

查询面拿到request对象里面的ActionFormBeanQ自动调用tag昄之?

ȝQ?

FormBean是Web层的数据表示Q他不能被传递到业务层;PO是持久层的数据表C,在特定情况下Q例如Hibernate中,他可以取代VO出现在业务层Q但是不POq是VO都必限制在业务层内使用Q最多到达Web层的ControlQ绝不能被扩散到View厅R?

FormBean和PO之间的数据{化是在Action中进行滴?

BTW:

JDO1.xq不能像Hibernate功能q样强大QPO不能q持久层,所以必d业务层用VOQ因此必d业务层进行大量的VO和PO的{化操作,相对于Hibernate来说Q编E比较烦琐?

当然咯,理论是一回事Q实际操作也不一定非要这样干Q你可以自行取舍Q在实际目中灵zM点,增加一点bad smellQ提高开发效率。只不过在大型项目中最好还是严丝合~,不然的话Q改版的时候会痛苦的很滴?/P>

]]>
վ֩ģ壺 99ȳ˾ƷȾþ| ŷղۺ| պŷƵ| ޾Ʒa| ӰҹƵ| avպav߹ۿ| ޾þþþþ77777| þ99ƷƵ| һɫþ88ۺ޾Ʒ| ޸һ| 99߹ۿƵվ| ŷ޹ۺAVþ | Ƶѹۿ| þó18վ | Ůɫվ| Ӱַ| ޹Ʒ| ʵ׾Ʒ| ŮվƵ| Ļ߹ۿ| þ޹˾Ʒ| avһ| ĻƵ߹ۿ| ޾Ʒ߹ۿ| þۺպ޾Ʒɫ| һػɫƬ߹ۿ | ëƬվ߹ۿ| ߾Ʒһ㽶| ޹˾þþƷ| ͵ͼƬ| ˳һ| Ļ߲| Ƶѹۿ| ůůձĻ| պϵ| ˳ɫ77777߹ۿ| ŷ޹Ʒþ| AV˾Ʒ| ޹һ߹ۿ| ѻ߹ۿ| 鶹Ƶѹۿ|