How "lazy=proxy" impacts final SQL for many-to-one?
I have done build-time bytecode instrumentation. I also add lazy="true" to joined side
I known many-to-one is the formal solution for foreign key. In most cases, we expect lazy loading foreign table.
How ever, I found no matter what is laze attribute value, final generated SQL keep no change.
I have two classes: Topic and Company. Topic has a field named company:
Code:
<many-to-one name="company" class="Company" lazy="proxy">
<column name="COMPANY" length="32" />
</many-to-one>
My tested HQL: select id, company from Topic
My expected SQL: select id, company from DT_TOPIC.
The actual Hibernate tools generated SQL:
Code:
select
topic0_.ID as col_0_0_,
topic0_.COMPANY as col_1_0_,
company1_.COMPID as COMPID409_,
company1_.COMPNAME as COMPNAME409_,
company1_.DESCRIPTION as DESCRIPT3_409_,
company1_.STATUS as STATUS409_
from
DT_TOPIC topic0_
inner join
XPC_COMPANY company1_
on topic0_.COMPANY=company1_.COMPID
This SQL has two weakness:
1. join foreign table
2. select all fields in foreign tables.
Why lazy loading does not effect?