Hi,
I started using Hibernate 1 month ago and now I'm stucked in some horrible performance degradation. I have a query that uses 6 tables making some sum, count, max and group by. The resulted method looks very nice but the execution time is almost 2s. I wrote the same method using PreparedStatement and Connection obtained from the Session object and surprise : it took 0.2s!
I also noticed that most of the queries take more time than using standard JDBC ! What can I do ?
Hibernate version: 2.1.4
Mapping documents:
Name and version of the database you are using: MySQL 4.0
The generated SQL (show_sql=true): "select userdeta0_.ID as ID0_, userplan2_.pk_user_plan as pk_user_plan1_, director1_.ID as ID2_, " + "userdeta0_.PARENTID as PARENTID0_, userdeta0_.FIRSTNAME as FIRSTNAME0_, " + "userdeta0_.LASTNAME as LASTNAME0_, userdeta0_.COMPANY as COMPANY0_, " + "userdeta0_.DEPARTMENT as DEPARTMENT0_, userdeta0_.PHONE as PHONE0_, userdeta0_.CELL as CELL0_, " + "userdeta0_.EMAIL as EMAIL0_, userdeta0_.PASSWORD as PASSWORD0_, userdeta0_.ADDRESS as ADDRESS0_, " + "userdeta0_.CITY as CITY0_, userdeta0_.STATE as STATE0_, userdeta0_.ZIPCODE as ZIPCODE0_, " + "userdeta0_.COUNTRY as COUNTRY0_, userdeta0_.DATECREATED as DATECRE16_0_, userdeta0_.ACTIVE as ACTIVE0_, " + "userdeta0_.EDITTIME as EDITTIME0_, userdeta0_.TOTALPAID as TOTALPAID0_, userdeta0_.CODE as CODE0_, " + "userdeta0_.REMARK as REMARK0_, userdeta0_.TYPE as TYPE0_, userdeta0_.DIRECT_PUBLISHING as DIRECT_23_0_, " + "userdeta0_.SEND_SLIDETOUR as SEND_SL24_0_, userdeta0_.use_terminus as use_ter25_0_, " + "userdeta0_.TEMPLATE as TEMPLATE0_, userdeta0_.USE_EBAY as USE_EBAY0_, " + "userdeta0_.EBAY_TOKEN as EBAY_TOKEN0_, userdeta0_.EBAY_TOKEN_EXPIRES as EBAY_TO29_0_, " + "userdeta0_.NEXT_INVOICE_DATE as NEXT_IN30_0_, userdeta0_.FIXED_RATE as FIXED_RATE0_, " + "userdeta0_.DIRID as DIRID0_, userdeta0_.RESELLERID as RESELLERID0_, " + "userplan2_.charge as charge1_, userplan2_.included_images as included3_1_, " + "userplan2_.additional_image_price as addition4_1_, userplan2_.self_service_audio as self_ser5_1_, " + "userplan2_.professional_audio_price as professi6_1_, " + "userplan2_.included_professional_audio as included7_1_, userplan2_.start_date as start_date1_, " + "userplan2_.end_date as end_date1_, userplan2_.fk_plan as fk_plan1_, userplan2_.fk_user as fk_user1_, " + "director1_.DESCRIPTION as DESCRIPT2_2_, director1_.TITLE as TITLE2_, " + "director1_.LEVEL as LEVEL2_, director1_.NUM as NUM2_, " + "director1_.PARENTS as PARENTS2_, director1_.DATECREATED as DATECREA7_2_, " + "director1_.OWNER as OWNER2_, director1_.ACTIVE as ACTIVE2_, director1_.HIDE as HIDE2_, " + "userdeta0_.ID as x0_0_, userplan2_.pk_user_plan as x1_0_, sum(payments4_.PAYMENT) as x2_0_, " + "sum(invoices3_.TOTAL_CHARGE) as x3_0_, count(invoices3_.pk_invoice) as x4_0_, count(payments4_.ID) as x5_0_, " + "max(invoices3_.END_DATE) as x6_0_, director1_.ID as x7_0_ " + "from users userdeta0_ " + "inner join directories director1_ on userdeta0_.DIRID=director1_.ID " + "inner join user_plan userplan2_ on userdeta0_.ID=userplan2_.fk_user " + "left outer join invoice invoices3_ on userdeta0_.ID=invoices3_.fk_user " + "left outer join payments payments4_ on invoices3_.pk_invoice=payments4_.fk_invoice " + "where (userdeta0_.TYPE=2 )" + "AND(userdeta0_.RESELLERID=2 )AND(userplan2_.start_date<=NOW() )" + "and((userplan2_.end_date>=NOW() )OR(userplan2_.end_date is null )) " + "group by userdeta0_.ID");
|