This topic has been archived. It cannot be replied.
-
工作学习 / 学科技术讨论 / 书上说如果完全不用lazy-load得话,会因为对象之间的互相引用而在查询时候不得不查询大量的不必要数据,若是引用关系较多,数据对象之间的引用关系就像是一张蜘蛛网,说不定查单一对象就得遍历所有的表。
请问大伙实际用HIBERNATE 时,真的都把LAZY-LOAD 设成FALSE 吗? 谢谢指教。
-who8mylunch(java中年失业男);
2009-10-28
{231}
(#5640716@0)
-
悟空JJ (part time 买房gent?)在楼下的帖子说的有理。因为对于web应用程序,一个request处理完了,session就结束。如果用lazy loading, 你会得到invalid session exception. (这也是面试常见问题)。你可能会问,可否将session 保持open. 理论上行,实际上不,因为这将影响到所谓的 scalability.
-james05(关不上的窗);
2009-10-28
{89}
(#5640728@0)
-
james05大侠所说的 SCALABILITY是指不同的JVM 吗?如果在同一个JVM 里 OPEN SESSION IN VIEW 也不好吗?
-who8mylunch(java中年失业男);
2009-10-28
{50}
(#5640749@0)
-
"一个request处理完了,session就结束。" --- You sure...?
-nicetomeetyou(蓦然回首彩虹跨天地);
2009-10-28
(#5640767@0)
-
Yes, as a best practice, after a HTTP request is handled, it's best to close the Hibernate session.Please do not confuse the Hibernate session with HTTP session. 如果你不懂,我可以与你分享一些网上资源。
-james05(关不上的窗);
2009-10-28
{103}
(#5640791@0)
-
long running session (conversational transaction)你不知道?hibernate session在request结束之后 为什么一定要close? 你要知道commit, flush, 和close的区别。
-crashingwaves(CherryHill);
2009-10-28
(#5640803@0)
-
You are the only one who is correct in this discussion.
-majorhomedepot(马甲后的炮);
2009-10-28
(#5641248@0)
-
The lifecycle of a session is bounded by the beginning and end of a logical transaction. Entity instances may be stored in HTTP session as session variables and may be shared by upcoming requests.you joke here.
-nicetomeetyou(蓦然回首彩虹跨天地);
2009-10-28
{14}
(#5640830@0)
-
如果在多个SERVLET REQUEST中重复使用一个HIBERNATE SESSION(把HIBERNATE SESSION 放到HTTP SESSION里面),就必须处理在HTTPSESSION超时后强制关闭HIBERNATE SESSION这种特殊情况
-who8mylunch(java中年失业男);
2009-10-28
(#5640983@0)
-
I read james05's post again, yes, it is best practice to close any transaction object whenever http request is completed, or, as a final defense, check and close it when session is destroyed.
-nicetomeetyou(蓦然回首彩虹跨天地);
2009-10-28
(#5641040@0)
-
long running session (conversational transaction)你不知道?hibernate session在request结束之后 为什么一定要close? 你要知道commit, flush, 和close的区别。 -crashingwaves(CherryHill); 19:31 (#5640803@0) Reply
-crashingwaves(CherryHill);
2009-10-28
(#5641042@0)
-
If you have low number of concurrent users, what you said is okay. But imagine the system needs to support hundreds, even thousands, of concurrent users. What you said is not scalable. See also the notes below posted by ejbEqHouse。
-james05(关不上的窗);
2009-10-28
(#5641109@0)
-
这和concurrency有什么关系,我倒是非常非常好奇了。大家是不是找到了servlet 2.5标准的一个大bug,或者是找到了JTA的一个大bug,震撼,非常震撼。麻烦大家解释一下。
-crashingwaves(CherryHill);
2009-10-28
(#5641140@0)
-
老兄, 你的程序真是这么写的?
-ejbeqhouse(ejbEqHouse);
2009-10-28
(#5641038@0)
-
我没这么写,我是顺着牛哥的思路怎么想
-who8mylunch(java中年失业男);
2009-10-28
(#5641045@0)
-
写不好,瞎写,向大虾们学习.:-)
-nicetomeetyou(蓦然回首彩虹跨天地);
2009-10-28
(#5641050@0)
-
牛哥说的没错,你难道不是这样设计的?
-crashingwaves(CherryHill);
2009-10-28
(#5641056@0)
-
To close a session is to release the JDBC connection. If you put a hibernate session into a http session, so you do not close it for a long time. Then why you need connection pool?I never put a hibernate session into a http session as a http session variable. If we do so, why we need n-tier? What is session facade and what is DAL/DAO?
-ejbeqhouse(ejbEqHouse);
2009-10-28
{156}
(#5641082@0)
-
不关闭HIBERNATE SESSION
-who8mylunch(java中年失业男);
2009-10-28
(#5641102@0)
-
SORRY, AGAIN. 不关闭HIBERNATE SESSION , 也可以关闭JDBC CONNECTION, 用SESSION.DISCONNECT() , 需要的时候再连上SESSION.RECONNECT()
-who8mylunch(java中年失业男);
2009-10-28
(#5641104@0)
-
Firstly, reconnect() is deprecated, you should use reconnect(Connection connection). How do you get a connection when you try to reconnect? I do not use this way, so I have no idea about it.I alway close a session when I finish a query or a transaction. In fact, I will open a session and close a session multiple times to handle a http request.
Secondly, all my database operations are handle in the data access layer. I donot think that it is good to put hibernate session into a http session. If to do so, we do not need n-tier.
-ejbeqhouse(ejbEqHouse);
2009-10-28
{343}
(#5641145@0)
-
"I alway close a session when I finish a query or a transaction. In fact, I will open a session and close a session multiple times to handle a http request." -- 你太厉害啦!
-nicetomeetyou(蓦然回首彩虹跨天地);
2009-10-28
(#5641181@0)
-
Ok. Show you a example. In a request, I need to do more than 20 business logical checking which involve multiple tables and each of those validation methods are in different class so that they are reusable.I do not think that we should pass a hibernate session between those validations. For each validation, I open a session and close it after I finish my query. It is so normal. Even you load a page for a request, you can not load all data in one class and one method except your application/database is not complex.
-ejbeqhouse(ejbEqHouse);
2009-10-28
{313}
(#5641224@0)
-
那很显然,你说的scenario就应该不是我们讨论的case了,对不对?
-crashingwaves(CherryHill);
2009-10-28
(#5641252@0)
-
what I said is that we should not put a hibernate session into a http session.
-ejbeqhouse(ejbEqHouse);
2009-10-28
(#5641263@0)
-
Right, then we need to put it somewhere else, correct? No where else can we put it?
-crashingwaves(CherryHill);
2009-10-28
(#5641288@0)
-
Modern frameworks support this feature. Both Spring Web Flow and SEAM support conversation scope, which is better than http session.
-majorhomedepot(马甲后的炮);
2009-10-28
(#5641326@0)
-
Let me explain what conversation scope is, it is smaller than http session scope. It is more likely to group some related request together.
-ejbeqhouse(ejbEqHouse);
2009-10-28
(#5641383@0)
-
I read your posts again and find I might have misread your opinion. You actually only have problem with putting hibernate session into http session. If you have a framework like SEAM or SWF 2.0, where conversation is available, youare right. But, if you don't have such framework support, I wonder how you answer CherryHill's question of where you put the hibernate session. If you really drill down, you can see SEAM and SWF 2.0 are putting hibernate session into http session to implement conversation scope.
-majorhomedepot(马甲后的炮);
2009-10-28
{282}
(#5641436@0)
-
I assume that what you mentioned "business logical checking" is a series of DB read operation, no commit is needed, then why don't you complete them one by one in ONE session?
-nicetomeetyou(蓦然回首彩虹跨天地);
2009-10-28
(#5641376@0)
-
Sorry, that is too much detail information. I need to work on my ETL applcation. I have a demo tomorrow morning.In one word, we need to access multiple tables and those methods are need to be reusable.
-ejbeqhouse(ejbEqHouse);
2009-10-28
{89}
(#5641404@0)
-
OK, understand. Thanks! In many scenarios, mid tier wrappers are heavier and heavier and are over-kill. absolutely a wrong way to treat db like a procedural process. The backbone should be high efficient SQL query, not reusable object.
-nicetomeetyou(蓦然回首彩虹跨天地);
2009-10-28
(#5641459@0)
-
reconnect() is deprecated because hibernate reconnects automatically for you and you don't have to call reconnect() by yourself.
-majorhomedepot(马甲后的炮);
2009-10-28
(#5641286@0)
-
Could you give me a link about it? Anyway here is from hibernate API which is different what you said:Deprecated. Manual reconnection is only needed in the case of application-supplied connections, in which case the reconnect(java.sql.Connection) for should be used.
-ejbeqhouse(ejbEqHouse);
2009-10-28
{164}
(#5641435@0)
-
How is it different? "Manual reconnection is only needed in case of..." means you don't need to reconnect manually unless ... You don't need because it is done by hibernate.
-majorhomedepot(马甲后的炮);
2009-10-28
(#5641471@0)
-
我这样设计: conn pool is global accessible, session picks a conn and release it right away when transc is done. you may save dat in cache in mid tier, so no conn creation is needed for better perf.my understanding, most obejct-data -boundles are session-specific. means they may be different in content, format based on different user/role.
-nicetomeetyou(蓦然回首彩虹跨天地);
2009-10-28
{143}
(#5641131@0)
-
震撼了,我非常地震撼了。surrounded by such stupidity is a very very strong feeling...不close Hibernate session就不能释放connection。苍天啊,拯救这帮迷途的羔羊吧,请赐予他们英文阅读能力,让他们能看懂书吧。
-crashingwaves(CherryHill);
2009-10-28
(#5641155@0)
-
So you put the hibernate session into a http session as a http session veriable? I do not know how you think about DAL/DAO.And reconnect() is deprecated, you should use reconnect(Connection connection). How do you get a connection when you try to reconnect? Maybe you could answer those two questions to me. I really would like to know.
-ejbeqhouse(ejbEqHouse);
2009-10-28
{213}
(#5641199@0)
-
It's a joy that 手里拿着Christen Bauer的书,看着你们在这里信口开河。It is really a joy。If you can't read the source code, read the book。Christen & Gavin don't lie, since they designed Hibernate。
-crashingwaves(CherryHill);
2009-10-28
(#5641219@0)
-
My application got a province gold award. And I also finished a SEAM project. I am working on database synchronization and ETL. I do not know what you are talking about.What I said is based on my experience. LOL, put your hibernate session into your http session.
-ejbeqhouse(ejbEqHouse);
2009-10-28
{94}
(#5641257@0)
-
I seriously doubt you worked in a SEAM project. Perhaps, you were not a lead or senior member in the project. Have you ever used conversation scope, which is one of the most selling point in SEAM?
-majorhomedepot(马甲后的炮);
2009-10-28
(#5641314@0)
-
I finished the SEAM project last year. It is one of the best in our company's applications. I build the application from beginning and design the key part of it.I donot work on it for a while. Give you a detail information: the Crystal Reports is not integrated with SEAM well last year. Dose it improve now?
-ejbeqhouse(ejbEqHouse);
2009-10-28
{148}
(#5641364@0)
-
Good for you. You may want to refresh your memory and take a look into the chapters about SEAM managed transaction in any SEAM book or its reference. SEAM was the first framework supporting extended session in conversation scope, whichis common now.
-majorhomedepot(马甲后的炮);
2009-10-28
{14}
(#5641397@0)
-
Let me explain what conversation scope is, it is smaller than http session scope. It is more likely to group some related request together. -ejbeqhouse(ejbEqHouse); 22:42 (#5641383@0)
-ejbeqhouse(ejbEqHouse);
2009-10-28
(#5641407@0)
-
I do not copy the explanation from anywhere. It is the concept in my mind.
-ejbeqhouse(ejbEqHouse);
2009-10-28
(#5641411@0)
-
Did you work on SEAM? Could answer my question about how integrate the report with it? If you did not work on it, you should not know right away. However it impressed me so much, even more than any other concept.
-ejbeqhouse(ejbEqHouse);
2009-10-28
(#5641422@0)
-
I did not integrate SEAM with Chrystal Report.
-majorhomedepot(马甲后的炮);
2009-10-28
(#5641482@0)
-
樱桃,听我劝一句。Christen Bauer的书 -- Yes I understand that he is one of the main contributors to Hibernate -- can only be treated as a text book. There are many problems it does not address for an enterprise application.So are Java / J2EE books. That's why we have best practices.
-james05(关不上的窗);
2009-10-28
{61}
(#5641333@0)
-
You know what you are talking about, right?
-crashingwaves(CherryHill);
2009-10-28
(#5641375@0)
-
嗯, I know. BTW, 这里是技术讨论。俺怎么感觉你跟其他的朋友有点不一样呢?大伙儿的经验,知识可能不一样,谁对谁错并不是最重要的,但只要大家经过讨论,互相学习,共同有所提高,这才是Sailor的宗旨之一。真正的高手,就应该拿得起,放得下。
-james05(关不上的窗);
2009-10-28
{34}
(#5641451@0)
-
+1 to the attitude. Open and healthy discussions help everyone! And, that is the only reason I am here.
-majorhomedepot(马甲后的炮);
2009-10-28
(#5641494@0)
-
+1. hibernate session 放在 http session 里不是不可以, 但90%以上的用法不会这么做。最常见的就是对于每个request把hibernate session绑在thread local上用完之后close。某些搞技术的国人毛病就是不够坦诚,有什么说什么就是了,觉得自己看了几本书,就非得云山雾罩高来高去的,有什嘛意思。
别回复哥,哥也不会再回复,飘过。。。
-xanada(㊣流水);
2009-10-28
{152}
(#5641514@0)
-
感谢理解。If you use a J2EE App Server, there is another way - let the app server handle all these routine stuffs for you. See the so-called "正解" of mine in the lower part of this msg thread.
-james05(关不上的窗);
2009-10-28
(#5641588@0)
-
这个误导太严重,不得不回了。Hibernate提供三种提取currentSession的方法,一种是绑定在ThreadLocal上,一种是绑定在JTA transaction上,一种是自定义。因为80%以上的enterprise application都使用application server, 所以最常用的应用都是绑定在JAT transaction上。
-crashingwaves(CherryHill);
2009-10-30
{1230}
(#5644428@0)
-
握手!
-james05(关不上的窗);
2009-10-30
(#5644910@0)
-
Out of curiosity, can the logical transaction in your framework cross multiple HTTP requests?Your statement here is only correct when your answer is yes. But, from your other posts in this thread, I guess your answer is no.
-majorhomedepot(马甲后的炮);
2009-10-28
{130}
(#5641279@0)
-
我觉得james大侠的意思是关掉HIBERNATE SESSION后,反正可以创建一个新的SESSION去绑定DETACHED 的对象(如果需要读后续内容)
-who8mylunch(java中年失业男);
2009-10-28
(#5640968@0)
-
你自己先把关掉session是什么意思搞清楚再说。
-crashingwaves(CherryHill);
2009-10-28
(#5641059@0)
-
我觉得还是 OPEN SESSION IN VIEW 应该比较好,各位大侠的立场在不同场景都有合理的地方,呵呵
和和稀泥。。。
-who8mylunch(java中年失业男);
2009-10-28
(#5641092@0)
-
session在.net里有in-proc, sqlsession, sqlserver三种, 至少用sqlserver的session不影响scalability, 不知道java的也应该有类似机制吧.
-mfcguy();
2009-11-9
(#5667753@0)
-
书上还说,如果不用lazy loading, 你应该设定fetching strategy。
-crashingwaves(CherryHill);
2009-10-28
(#5640800@0)