-->
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: map-key-many-to-many: 1+N select problem
PostPosted: Wed Mar 22, 2006 6:28 am 
Regular
Regular

Joined: Tue Nov 16, 2004 6:36 pm
Posts: 62
Location: Zürich
Hibernate version: 3.1

Hello, I use a <map> with a <map-key-many-to-many> key, that is the key of the map is another entity.

Now I try to accomplish that the map is eagerly loaded, not only the "id's" of the map (I do see that that is what's happening) but also the entity used as the key.

<class name='ttt' table='ttt'>
<id name='id'/>
...
<map name='weights' table='xxx' lazy='false' fetch='join'>
<key column='ttt_id'/>
<map-key-many-to-many column='asset_id' class='Asset'/>
<element ... />
</map>
</class>

<class name='Asset' table='asset'>
<id name='id'/>
...
</class>

In the reference manual I cannot find any example of using map-key-many-to-many like this (inly in "ternary associations", 6.3.4, where it is used with one-to-many i.e. the map element doesn't have a table but an external entity is used) but I guess it would be the same for one-to-many or many-to-many mappings (instead of element).

Now I cannot convince hibernate to fetch the assets (the keys of the map) eagerly. It generates many select queries when accessing the map.

I would like to see a select query like this when accessing the map:
select ..
from ttt t left join xxx x on t.id=x.ttt_id
left join asset a on a.id=xxx.asset_id

Instead, we get the 1+N select problem:

first I see this query:
select ..
from ttt t left join xxx x on t.id=x.ttt_id

then I get thousands of select queries to fetch each asset individually :(.

I don't see any attribute or way to map-key-many-to-many to change this behavious.

Is it possible in some way to avoid this problem?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 23, 2006 10:18 am 
Regular
Regular

Joined: Tue Nov 16, 2004 6:36 pm
Posts: 62
Location: Zürich
Hello,

My questions mostly seem to remain without answers.
Still I'm quit stuck in this regard: is there an efficient way of using
map-key-many-to-many or do I have to avoid it alltogether?

Is my question too trivial, does noone know the anser, or even not understand the question?

I would already be happy knowing that noone knows the answer, so any kind of answer is greatly appreciated :)

Thanks,

Peter


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2008 6:33 am 
Newbie

Joined: Mon Nov 15, 2004 1:52 pm
Posts: 7
I guess the poster doesn't expect an answer anymore, but in case other people find this thread (as I did) trying to do the same thing, you can find a beginning of an answer (but not working :/) here : http://forum.hibernate.org/viewtopic.ph ... 82#2400082


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.