我正在学习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_
任何见解或帮助都非常值得赞赏。
答案 0 :(得分:1)
好吧,我认为执行相同的查询5次不太可能是加载页面的最有效方式。
理解Hibernate等工具在幕后做什么很重要,也就是说你不能假设一切都会发挥作用。因此,查看生成的SQL肯定是正确的做法。
但是,您只能通过分析应用程序来回答您的问题。如果您发现查询需要25秒才能执行,那么您应该查看Oracle诊断工具。