I am learning Hibernate and playing around with it using Eclipse Helios as IDE, Oracle11g as database and Glassfish 3 as server. I am following a simple application
(JSF+Spring+Hibernate)
I have found a simple select and insert is quite slow, almost taking 25 seconds for select query. I would like to know why is it slow when compared to plain JDBC.
Below is from server.log, when I refresh my page, same query is executing five times. Is this a reason for slowness?
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_
Any insight or help is highly appreciable.
Well I would image that performing the same query 5 times is unlikely to be the most efficient way to load a page.
It’s important to understand what tools such as Hibernate are doing under the covers, i.e. you can’t just assume that everything will perform. So looking at the generated SQL is certainly the right thing to be doing.
However, you can only really answer your question by profiling your application. If you find that a query is taking 25 seconds to execute you should take a look at the Oracle diagnostic tools.