-->
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.  [ 3 posts ] 
Author Message
 Post subject: 2 many-to-one to the same table
PostPosted: Wed Oct 27, 2004 9:23 am 
Newbie

Joined: Fri Apr 16, 2004 10:55 pm
Posts: 5
Hibernate version:2.1.6

Hi;

This is my first question to this forum, since I had to do allot of reading before bothering people with questions :)

I have a strange reaction from hibernate, and I can't get it...

I have a class called "Shipment" it contains allot of info., another class called "ServiceAreaCode" that contain cities and so...

each Shipment contain 2 ServiceAreaCode objects, one is origin the other is destination...

simply... (This is a part of the map only)


Code:
<hibernate-mapping package="trackingApp.data">
<class name="Shipment" table="Shipment">
<id
column="shipmentID"
name="ShipmentID"
type="java.lang.Long"
>
<generator class="identity" />
</id>

<many-to-one
class="trackingApp.data.ServiceAreaCode"   
name="OCodeID"
not-null="true"
>
<column name="orgCodeID" />
</many-to-one>

<many-to-one
class="trackingApp.data.ServiceAreaCode"   
name="DCodeID"
not-null="true"
>
<column name="dstCodeID" />
</many-to-one>
.
.
.


now when I use only one ServiceAreaCode, it get eagerly fetched, but when I use both 2 calls are issued to the database, which make significant drop in performance.

Why? and how can I eagrly fetch these 2 objects? FetchMode doesn't work, I tried it.

I know some people would say that this is not a many-to-one relation ship, since there is 2 links to ServiceAreaCode, if my mapping is wrong, please correct me, but still I need the same logic.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 27, 2004 9:29 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
i don't know exactly ... but you can try ;)

I think per default hibernate only fetchs one association eagerly ... if you want more, you need to set "hibernate.max_fetch_depth" to a value greater than 1 ...
If you set it to 2, then 2 associations will be included in the outer-join ...

But if that will work in your case, i don't now, sorry ...


gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 28, 2004 2:58 am 
Newbie

Joined: Fri Apr 16, 2004 10:55 pm
Posts: 5
"hibernate.max_fetch_depth" is good if you have a tree relation, I mean if you have table->table->table...

What I want is

TableA has 2 references in tableB, but not in a collection, each is an object by itself.


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