-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: Strange! How lazy loading impacts many-to-one?
PostPosted: Wed Jan 17, 2007 10:08 am 
Newbie

Joined: Tue Jan 17, 2006 9:48 pm
Posts: 16
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?


Top
 Profile  
 
 Post subject: Who can help me?
PostPosted: Wed Jan 24, 2007 4:43 am 
Newbie

Joined: Tue Jan 17, 2006 9:48 pm
Posts: 16
I have done build-time bytecode instrumentation and try all configurations on lazy. The problem remains!


Top
 Profile  
 
 Post subject: Who can help me?
PostPosted: Wed Jan 24, 2007 4:43 am 
Newbie

Joined: Tue Jan 17, 2006 9:48 pm
Posts: 16
I have done build-time bytecode instrumentation and try all configurations on lazy. The problem remains!


Top
 Profile  
 
 Post subject: Who can help me?
PostPosted: Wed Jan 24, 2007 4:44 am 
Newbie

Joined: Tue Jan 17, 2006 9:48 pm
Posts: 16
I have done build-time bytecode instrumentation and try all configurations on lazy. The problem remains!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 12:53 pm 
Newbie

Joined: Fri Mar 26, 2004 8:51 am
Posts: 6
Quote:
My tested HQL: select id, company from Topic

How it imagines that hibernate can give back the Company object that is in select if it does not do join against the corresponding table?


Top
 Profile  
 
 Post subject: Join against?
PostPosted: Wed Jan 24, 2007 9:32 pm 
Newbie

Joined: Tue Jan 17, 2006 9:48 pm
Posts: 16
What "join against " mean?
You mean I should write the hql as this?
Code:
select id, company from Topic left join Company


I have defined such relationship in O/R mapping. It is terrible if join all foreign reference tables.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 12:15 pm 
Newbie

Joined: Fri Mar 26, 2004 8:51 am
Posts: 6
If your HQL query includes the company object in the select clause, is logical that corresponding SQL query includes a JOIN against the corresponding table.
Sorry for my English, is not my natural idiom.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 12:23 pm 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
I think when you write

select id, company from Topic in HQL,

hibernate interprets it as that you want id and the Company object corresponding to each Topic and hence it joins company table and select all columns.

Have a look at the result set, I am sure that it will be returning the company object instead of its id.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 28, 2007 2:49 am 
Newbie

Joined: Tue Jan 17, 2006 9:48 pm
Posts: 16
I have found two ways to active lazy loading even without byte code instrument.
1. select id, company.id from Topic
2. from Topic

Obviously, Hibernate love the HQL without select sub clause very much. I just wonder why Hibernate request byte code instrument.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.