0

In my project we have hbm.xml file which is fetch="select" for one-to-many for all relation tables.

For ex: One school is having many classrooms and one classroom will have many children

so in my hbm file

school.hbm.xml
<set name="classrooms" lazy="false" fetch="select">

classroom.hbm.xml
<set name="children" lazy="false" fetch="select">

There is a case where I want to fetch only list of schools which are based on classroom div = 'A'. But because of this mapping hibernate is doing select for classroom as well which I don't want in this case.

Please help me how can I avoid doing unnecessary select with classroom. Is there anyway to override this fetch mode and join only with School and classroom and not with children

I tried with multiple options but no luck. Really appreciate for your inputs.

sats
  • 167
  • 1
  • 2
  • 10

1 Answers1

0

No - I believe you cannot override EAGER mappings, neither using find, query nor criteria queries. E.g see StackOverflow thread. Overriding LAZY is though easy.

hbm.xml file which is fetch="select" for one-to-many for all relation tables

...seems like a bad default choice - that's why the opposite is Hibernate's own default choice.

Usually it's a good practice to stay low and lazy in mappings, and use queries when you're eager.

Community
  • 1
  • 1
Jens X Augustsson
  • 1,214
  • 12
  • 13
  • Thanks for your response. Agree but we have a situation where we need to load some mapping objects eagerly. Now we cannot do change that mapping. – sats Sep 03 '15 at 22:15