限制Groovy中相同GORM对象的执行

时间:2018-07-04 12:13:45

标签: hibernate groovy gorm

我是groovy的新手。在我的项目中,我使用GORM对象从db获取数据。当我调用对象以获取数据时,它会多次执行。我不知道为什么要执行。当我看到休眠日志时使用同一对象获取数据后,便有更多的对象在执行。

例如:

Country country = Country.findByCountryCode('all');

如果我调用上述对象,则在休眠状态下获取以下日志

    Hibernate: select * from ( select this_.id as id1_79_0_, this_.version as version2_79_0_, this_.admin_instructions_for_use_id as admin_instructions3_79_0_, this_.admin_faq_id as admin_faq_id4_79_0_, this_.contact as contact5_79_0_, this_.country_id as country_id6_79_0_, this_.date_display_format as date_display_forma7_79_0_, this_.default_language as default_language8_79_0_, this_.distributors_id as distributors_id9_79_0_, this_.ecko_faq_id as ecko_faq_id10_79_0_, this_.ecos_faq_id as ecos_faq_id11_79_0_, this_.features_id as features_id12_79_0_, this_.footer_logo_left_id as footer_logo_left_13_79_0_, this_.footer_logo_right_id as footer_logo_right14_79_0_, this_.instructions_for_use_id as instructions_for_15_79_0_, this_.language_id as language_id16_79_0_, this_.license_agreement_id as license_agreement17_79_0_, this_.name_display_format as name_display_form18_79_0_, this_.participate as participate19_79_0_, this_.terms_of_use_id as terms_of_use_id20_79_0_, this_.use_default_format as use_default_forma21_79_0_, this_.user_guide_id as user_guide_id22_79_0_ from country_configuration this_ where this_.country_id=? and this_.language_id=? ) where rownum <= ?
    Hibernate: select * from ( select this_.id as id1_79_0_, this_.version as version2_79_0_, this_.admin_instructions_for_use_id as admin_instructions3_79_0_, this_.admin_faq_id as admin_faq_id4_79_0_, this_.contact as contact5_79_0_, this_.country_id as country_id6_79_0_, this_.date_display_format as date_display_forma7_79_0_, this_.default_language as default_language8_79_0_, this_.distributors_id as distributors_id9_79_0_, this_.ecko_faq_id as ecko_faq_id10_79_0_, this_.ecos_faq_id as ecos_faq_id11_79_0_, this_.features_id as features_id12_79_0_, this_.footer_logo_left_id as footer_logo_left_13_79_0_, this_.footer_logo_right_id as footer_logo_right14_79_0_, this_.instructions_for_use_id as instructions_for_15_79_0_, this_.language_id as language_id16_79_0_, this_.license_agreement_id as license_agreement17_79_0_, this_.name_display_format as name_display_form18_79_0_, this_.participate as participate19_79_0_, this_.terms_of_use_id as terms_of_use_id20_79_0_, this_.use_default_format as use_default_forma21_79_0_, this_.user_guide_id as user_guide_id22_79_0_ from country_configuration this_ where this_.country_id=? and this_.language_id=? ) where rownum <= ?
    Hibernate: select * from ( select this_.id as id1_79_0_, this_.version as version2_79_0_, this_.admin_instructions_for_use_id as admin_instructions3_79_0_, this_.admin_faq_id as admin_faq_id4_79_0_, this_.contact as contact5_79_0_, this_.country_id as country_id6_79_0_, this_.date_display_format as date_display_forma7_79_0_, this_.default_language as default_language8_79_0_, this_.distributors_id as distributors_id9_79_0_, this_.ecko_faq_id as ecko_faq_id10_79_0_, this_.ecos_faq_id as ecos_faq_id11_79_0_, this_.features_id as features_id12_79_0_, this_.footer_logo_left_id as footer_logo_left_13_79_0_, this_.footer_logo_right_id as footer_logo_right14_79_0_, this_.instructions_for_use_id as instructions_for_15_79_0_, this_.language_id as language_id16_79_0_, this_.license_agreement_id as license_agreement17_79_0_, this_.name_display_format as name_display_form18_79_0_, this_.participate as participate19_79_0_, this_.terms_of_use_id as terms_of_use_id20_79_0_, this_.use_default_format as use_default_forma21_79_0_, this_.user_guide_id as user_guide_id22_79_0_ from country_configuration this_ where this_.country_id=? and this_.language_id=? ) where rownum <= ?
    Hibernate: select * from ( select this_.id as id1_79_0_, this_.version as version2_79_0_, this_.admin_instructions_for_use_id as admin_instructions3_79_0_, this_.admin_faq_id as admin_faq_id4_79_0_, this_.contact as contact5_79_0_, this_.country_id as country_id6_79_0_, this_.date_display_format as date_display_forma7_79_0_, this_.default_language as default_language8_79_0_, this_.distributors_id as distributors_id9_79_0_, this_.ecko_faq_id as ecko_faq_id10_79_0_, this_.ecos_faq_id as ecos_faq_id11_79_0_, this_.features_id as features_id12_79_0_, this_.footer_logo_left_id as footer_logo_left_13_79_0_, this_.footer_logo_right_id as footer_logo_right14_79_0_, this_.instructions_for_use_id as instructions_for_15_79_0_, this_.language_id as language_id16_79_0_, this_.license_agreement_id as license_agreement17_79_0_, this_.name_display_format as name_display_form18_79_0_, this_.participate as participate19_79_0_, this_.terms_of_use_id as terms_of_use_id20_79_0_, this_.use_default_format as use_default_forma21_79_0_, this_.user_guide_id as user_guide_id22_79_0_ from country_configuration this_ where this_.country_id=? and this_.language_id=? ) where rownum <= ?
Hibernate: select * from ( select this_.id as id1_79_0_, this_.version as version2_79_0_, this_.admin_instructions_for_use_id as admin_instructions3_79_0_, this_.admin_faq_id as admin_faq_id4_79_0_, this_.contact as contact5_79_0_, this_.country_id as country_id6_79_0_, this_.date_display_format as date_display_forma7_79_0_, this_.default_language as default_language8_79_0_, this_.distributors_id as distributors_id9_79_0_, this_.ecko_faq_id as ecko_faq_id10_79_0_, this_.ecos_faq_id as ecos_faq_id11_79_0_, this_.features_id as features_id12_79_0_, this_.footer_logo_left_id as footer_logo_left_13_79_0_, this_.footer_logo_right_id as footer_logo_right14_79_0_, this_.instructions_for_use_id as instructions_for_15_79_0_, this_.language_id as language_id16_79_0_, this_.license_agreement_id as license_agreement17_79_0_, this_.name_display_format as name_display_form18_79_0_, this_.participate as participate19_79_0_, this_.terms_of_use_id as terms_of_use_id20_79_0_, this_.use_default_format as use_default_forma21_79_0_, this_.user_guide_id as user_guide_id22_79_0_ from country_configuration this_ where this_.country_id=? and this_.language_id=? ) where rownum <= ?
    Hibernate: select * from ( select this_.id as id1_79_0_, this_.version as version2_79_0_, this_.admin_instructions_for_use_id as admin_instructions3_79_0_, this_.admin_faq_id as admin_faq_id4_79_0_, this_.contact as contact5_79_0_, this_.country_id as country_id6_79_0_, this_.date_display_format as date_display_forma7_79_0_, this_.default_language as default_language8_79_0_, this_.distributors_id as distributors_id9_79_0_, this_.ecko_faq_id as ecko_faq_id10_79_0_, this_.ecos_faq_id as ecos_faq_id11_79_0_, this_.features_id as features_id12_79_0_, this_.footer_logo_left_id as footer_logo_left_13_79_0_, this_.footer_logo_right_id as footer_logo_right14_79_0_, this_.instructions_for_use_id as instructions_for_15_79_0_, this_.language_id as language_id16_79_0_, this_.license_agreement_id as license_agreement17_79_0_, this_.name_display_format as name_display_form18_79_0_, this_.participate as participate19_79_0_, this_.terms_of_use_id as terms_of_use_id20_79_0_, this_.use_default_format as use_default_forma21_79_0_, this_.user_guide_id as user_guide_id22_79_0_ from country_configuration this_ where this_.country_id=? and this_.language_id=? ) where rownum <= ?

请任何人指导我解决此问题。谢谢。

0 个答案:

没有答案