Announcement Announcement Module
Collapse
No announcement yet.
Best way on HibernateTemplate? response is vary slow Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Best way on HibernateTemplate? response is vary slow

    Code:
    public List<User> findAll() {
    		try {			
    			return this.getHibernateTemplate().find("from User user");
    		} catch(DataAccessException ex) {
    			ex.printStackTrace();
    		}
    		return null;
    	}
    my database only has 50 thousand records, and data response is really slow in unit test.
    when i change hibernate property

    Code:
    <prop key="hibernate.show_sql">false</prop>
    and rerun the test, the console produces

    Code:
    Hibernate: select userdetail0_.user_detail_id as user1_0_1_, userdetail0_.achievements as achievem2_0_1_, userdetail0_.background_check as background3_0_1_, userdetail0_.expected_salary as expected4_0_1_, userdetail0_.lang_spoken as lang5_0_1_, userdetail0_.lang_written as lang6_0_1_, userdetail0_.languages as languages0_1_, userdetail0_.other_language as other8_0_1_, userdetail0_.possess_passport as possess9_0_1_, userdetail0_.resume_date_modified as resume10_0_1_, userdetail0_.resume_date_upload as resume11_0_1_, userdetail0_.resume_filename as resume12_0_1_, userdetail0_.skills as skills0_1_, userdetail0_.subscribe_newsletter as subscribe14_0_1_, userdetail0_.trainings as trainings0_1_, userdetail0_.user_id as user20_0_1_, userdetail0_.willing_to_holidays_weekends as willing16_0_1_, userdetail0_.willing_to_relocate as willing17_0_1_, userdetail0_.willing_to_shift_schedules as willing18_0_1_, userdetail0_.willing_to_work_overseas as willing19_0_1_, user1_.user_id as user1_1_0_, user1_.account_type_id as account2_1_0_, user1_.activated as activated1_0_, user1_.activation_code as activation4_1_0_, user1_.active as active1_0_, user1_.address_details as address6_1_0_, user1_.alternate_email as alternate7_1_0_, user1_.date_activated as date8_1_0_, user1_.date_created as date9_1_0_, user1_.date_last_login as date10_1_0_, user1_.date_modified as date11_1_0_, user1_.date_of_birth as date12_1_0_, user1_.email as email1_0_, user1_.firstname as firstname1_0_, user1_.flag as flag1_0_, user1_.group_id as group16_1_0_, user1_.lastname as lastname1_0_, user1_.middlename as middlename1_0_, user1_.mobile_number as mobile19_1_0_, user1_.password as password1_0_, user1_.phone_number as phone21_1_0_, user1_.profile_picture as profile22_1_0_ from user_details userdetail0_ inner join users user1_ on userdetail0_.user_id=user1_.user_id where userdetail0_.user_id=?
    Hibernate: select userdetail0_.user_detail_id as user1_0_1_, userdetail0_.achievements as achievem2_0_1_, userdetail0_.background_check as background3_0_1_, userdetail0_.expected_salary as expected4_0_1_, userdetail0_.lang_spoken as lang5_0_1_, userdetail0_.lang_written as lang6_0_1_, userdetail0_.languages as languages0_1_, userdetail0_.other_language as other8_0_1_, userdetail0_.possess_passport as possess9_0_1_, userdetail0_.resume_date_modified as resume10_0_1_, userdetail0_.resume_date_upload as resume11_0_1_, userdetail0_.resume_filename as resume12_0_1_, userdetail0_.skills as skills0_1_, userdetail0_.subscribe_newsletter as sub
    yes its the query, it will stop until it gets to the # mo records in the table.
    what im missing here?

  • #2
    And why should it be fast? It loads 50000 records, converts them into objects puts them in a list... There is a lot going on... With some luck you also have some bad mappings in your user object resulting in additional queries which in a bad situation can load your whole database in memory...

    IN general a findall isn't the wisest thing to do ...

    Comment

    Working...
    X