1

I have a really simple query to select all rows from a table. In hibernate it always takes about 17-18 seconds. I specified, show_sql to be true. I copied the sql command directly to mysql and it took 0.00022 seconds...

this is the query:

SELECT 
    organizati0_.id AS id1_5_,
    organizati0_.adminList AS adminLis2_5_,
    organizati0_.demoAccount AS demoAcco3_5_,
    organizati0_.disabled AS disabled4_5_,
    organizati0_.enduserCredits AS enduserC5_5_,
    organizati0_.name AS name6_5_,
    organizati0_.pushNotificationRoom AS pushNoti7_5_,
    organizati0_.totalLicenses AS totalLic8_5_,
    organizati0_.usedLicenses AS usedLice9_5_
FROM
    organization organizati0_

this is the code for the query:

Session session = ThreadSessionHolder.getThreadSession();
Query query = session.createQuery("from Organization ");
List list = query.list();
return list;

any ideas? this is driving me nuts

Moshe Shaham
  • 15,448
  • 22
  • 74
  • 114
  • 1
    It's more likely to be the data retrieval from the server and creating java objects that at fault here. Notice that you are pulling the entire table – e4c5 Feb 14 '17 at 14:27
  • Is there any associations on the organisation entity? Could it be that some of them are eager? What's the number of records? – Dmitry Gusev Feb 14 '17 at 14:27
  • If you make the query on MySql always is going to be fast, think about each Organization object creation when you ask hibernate to return the whole table. You can put your organization table and see if we can make it perform better, like if you have some relationships, you can put them as lazy and your Organization object would be lighter. – mvlaicevich Feb 14 '17 at 14:27
  • 1
    http://stackoverflow.com/questions/6609645/simple-hibernate-query-returning-very-slowly – James Jithin Feb 14 '17 at 14:28
  • all of my references are annotated with lazy fetch. and @JamesJithin, i've already been through every answer there... – Moshe Shaham Feb 14 '17 at 14:37

1 Answers1

0

I found the issue.

I was performing an initialization operation in the constructor which shouldn't be done when selecting all

Moshe Shaham
  • 15,448
  • 22
  • 74
  • 114