0

我正在学习 Hibernate,并使用 Eclipse Helios 作为 IDE、Oracle11g 作为数据库和 Glassfish 3 作为服务器来使用它。我正在关注一个简​​单的应用程序 (JSF+Spring+Hibernate)

我发现一个简单的选择和插入非常慢,选择查询几乎需要 25 秒。我想知道为什么它比普通的 JDBC 慢。

以下来自 server.log,当我刷新页面时,相同的查询执行了五次。这是慢的原因吗?

INFO: Hibernate: select customer0_.CUSTOMER_ID as CUSTOMER1_0_, 
customer0_.NAME as NAME0_, customer0_.ADDRESS as ADDRESS0_, customer0_.
CREATED_DATE as CREATED4_0_ from scott.customer customer0_

INFO: Hibernate: select customer0_.CUSTOMER_ID as CUSTOMER1_0_, 
customer0_.NAME as NAME0_, customer0_.ADDRESS as ADDRESS0_, customer0_.
CREATED_DATE as CREATED4_0_ from scott.customer customer0_

INFO: Hibernate: select customer0_.CUSTOMER_ID as CUSTOMER1_0_, 
customer0_.NAME as NAME0_, customer0_.ADDRESS as ADDRESS0_, customer0_.
CREATED_DATE as CREATED4_0_ from scott.customer customer0_


INFO: Hibernate: select customer0_.CUSTOMER_ID as CUSTOMER1_0_, 
customer0_.NAME as NAME0_, customer0_.ADDRESS as ADDRESS0_, customer0_.
CREATED_DATE as CREATED4_0_ from scott.customer customer0_


INFO: Hibernate: select customer0_.CUSTOMER_ID as CUSTOMER1_0_, customer0_.
NAME as NAME0_, customer0_.ADDRESS as ADDRESS0_, customer0_.
CREATED_DATE as CREATED4_0_ from scott.customer customer0_

任何见解或帮助都是非常可观的。

4

1 回答 1

1

好吧,我认为执行相同的查询 5 次不太可能是加载页面的最有效方式。

了解 Hibernate 等工具在幕后所做的工作很重要,也就是说,您不能只是假设一切都会执行。因此,查看生成的 SQL 肯定是正确的做法。

但是,您只能通过分析您的应用程序来真正回答您的问题。如果您发现执行查询需要 25 秒,您应该查看 Oracle 诊断工具。

于 2012-11-25T22:29:49.550 回答