Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Too much information is fetched
PostPosted: Fri Sep 19, 2003 1:10 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Hello.

I have Company and Tool entities.

Every tool belongs to exactly one company (there is COMPANY_ID field in the TOOL table).

Company.hbm.xml has

<set name="tools" inverse="true">
<key column="COMPANY_ID"/>
<one-to-many class="eg.Tool"/>
</set>

and Tool.hbm.xml has

<many-to-one name="company" column="COMPANY_ID" not-null="true" />

The problem is: when I load tool by its ID, I'm not interested in its "parent" company. But Hibernate uses join to fetch everything. If I set outer-join attribute of many-to-one to "false", everything works fine but I can not access tool.getCompany().getName() in the case I need it.

Is there a way to disable join for particular relationship while be still able to access parent object later?


Top
 Profile  
 
 Post subject: try lazy
PostPosted: Fri Sep 19, 2003 2:20 pm 
Newbie

Joined: Fri Sep 19, 2003 2:15 pm
Posts: 1
I think there is a part about lazy initialization. Try setting lazy=true

it might be just for Collection, I am very new to this also

_________________
Paul... Paul Dhaliwal ... Pritpal Dhaliwal ... Pritpal Singh Dhaliwal ... ... ....


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 19, 2003 4:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1812
Location: Austin, TX
Quote:
but I can not access tool.getCompany().getName() in the case I need it.


Why not? Are you getting an error? If so, what is the error? How about showing the mapping for Company and Tool? And a simple code snippet showing what you are trying?

I do this all over my code and it works fine.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 19, 2003 5:35 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
2pritpal : no, "lazy" is not valid attribute for <many-to-one>

2steve: oops. Copying code snipets I have found the error. Totally my fault. My peoblem was NullPointerException accessing .getName() and as I have found, I was working with tool actually having COMPANY_ID=NULL. So Hibernate was right returning null from getCompany().

sorry.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 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.