-->
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.  [ 8 posts ] 
Author Message
 Post subject: lazy load problem
PostPosted: Fri May 28, 2004 12:52 am 
Newbie

Joined: Thu May 27, 2004 10:06 pm
Posts: 3
I have a one to many relationship b/w Company and Activity.
When I load an instance of Activity using its Primary Key(activityId) the company object is also loaded. How can I stop this from happening ?

Info:
hibernate-2.1, Oracle8, query code:
List messages = newSession.find(" from hibernate.CompanyActivity as activity where activity.activityId=327");

The 2 hbm.xml file snippets are ...
1/. Company.hbm.xml
<class
name="hibernate.Company"
table="COMPANY"
>

<id
name="companyId"
type="java.lang.Long"
column="COMPANY_ID"
>
<generator class="assigned" />
</id>

<property
name="name"
type="java.lang.String"
column="NAME"
not-null="true"
length="200"
/>
<!-- bi-directional one-to-many association to Activity -->
<set
name="companyActivity"
lazy="true"
inverse="true"
>
<key>
<column name="COMPANY_ID" />
</key>
<one-to-many
class="hibernate.CompanyActivity"
/>
</set>


2/.
<class
name="hibernate.CompanyActivity"
table="ACTIVITY"
>

<id
name="activityId"
type="java.math.BigDecimal"
column="ACTIVITY_ID"
>
<generator class="sequence">
<param name="sequence">SEQ_PK_ACTIVITY</param>
</generator>
</id>
<!-- bi-directional many-to-one association to Company -->
<many-to-one
name="company"
class="hibernate.AdtCompany"
not-null="true"
outer-join="true"
cascade="none"
>
<column name="COMPANY_ID" />
</many-to-one>

-- I also tried with outer-join="false", and not-null="false".



log4j.properties:
#This is only for hello's test !!!
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### root logger option ###
log4j.rootLogger=warn, stdout
### Hibernate logging options ###
log4j.logger.net.sf.hibernate=info
### log JDBC bind parameters ###
log4j.logger.net.sf.hibernate.type=debug
### log PreparedStatement cache activity ###
log4j.logger.net.sf.hibernate.ps.PreparedStatementCache=info

In the logs i can see the 2 queries being executed and statements like:
Hibernate: select blah blah....
221:37:29,148 DEBUG BigDecimalType:68 - returning '327' as column: ACTIVITY_1_
1:37:29,228 DEBUG LongType:68 - returning '717' as column: COMPANY_ID
Hibernate: select
Hibernate: select company0_.COMPANY_ID blah blah....
1:37:29,278 DEBUG LongType:46 - binding '717' to parameter: 1

TIA,
Rahul


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 3:32 am 
Regular
Regular

Joined: Wed May 12, 2004 3:03 am
Posts: 51
Location: France
Hi,

Do you do any operation on the result? Is it the only code your are testing?

Thanks,

Charles


Top
 Profile  
 
 Post subject: lazy load problem
PostPosted: Fri May 28, 2004 3:46 am 
Newbie

Joined: Thu May 27, 2004 10:06 pm
Posts: 3
The queries are executed in the find call.

But i do perform a couple of operations on the object after the find.

Thanks,
rahul


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 4:00 am 
Regular
Regular

Joined: Wed May 12, 2004 3:03 am
Posts: 51
Location: France
If you do some work on the objects, I think it's normal to have a hole representation of an object... depending of your work...

Could you see if the loading is done in two phases or in once?


Top
 Profile  
 
 Post subject: lazy load problem
PostPosted: Fri May 28, 2004 4:33 am 
Newbie

Joined: Thu May 27, 2004 10:06 pm
Posts: 3
Actually I am not working on the company object. Only on the Activity object. And so I dont' need to load the company object.
The loading is done in 2 phases as can be seen by 2 separate queries in the log.

Is there any info. that I am missing ?

thanks for the quick responses !!!

Thanks,
Rahul


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 5:18 am 
Regular
Regular

Joined: Wed May 12, 2004 3:03 am
Posts: 51
Location: France
I'm sorry, but I won't be able to help you more...

Hope you'll find a solution.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 5:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
use "join fetch" in your hql


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 9:24 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You have not enabled proxying. Please read the Hibernate documentation properly before posting here. TIA.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.