-->
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.  [ 5 posts ] 
Author Message
 Post subject: mapping question (many-to-many via composite key)
PostPosted: Fri Mar 28, 2008 11:51 am 
Newbie

Joined: Fri Mar 28, 2008 10:21 am
Posts: 4
struggling with "collection is not associated with any session" exception. this is what i have:

Code:
client
    id unique
    counterparty not unique
   
rule
    counterparty not unique
    name
   
    composite unique index (counterparty, name)


one client can have many rules:
Code:
select client.id, rule.name from client, rule where client.counterparty = rule.counterparty


same rule can belong to many clients

Code:
class Client {
    int id;
    Set<Rule> rules = new HashSet<Rule>();
}

class Rule {
    String name;
}


i would like to load all clients and for each client load all rules that belong to it. all in one shot as my app initializes.

it seems like the best way to map is to use <set> inside of the client and either map it as a value or an entity:

Code:
<set lazy="false" fetch="subselect" mutable="false" name="rules" table="Rule">
    <key column="counterparty" property-ref="counterparty" />
    <composite-element class="Rule">
        <property name="name" />
    </composite-element>
</set>


or

Code:
<set lazy="false" fetch="subselect" mutable="false" name="rules" table="Rule">
    <key column="counterparty" property-ref="counterparty" />
    <one-to-many class="Rule" />
</set>


in both cases i get "collection is not associated with any session" exception when i run hibernateTemplate.loadAll(Client.class); if i remove the <set> from Client mapping file, everything works fine, so my hibernate machinery is OK.

Code:
<class name="Rule" table="rule">
    <composite-id>
        <key-property name="counterparty" />
        <key-property name="name" />
    </composite-id>
</class>


if i switch to fetch="join", i get back a client for each rule, which is not what i want, since i only have a handful of clients.

any suggestions on how this mapping can be changed?

thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 29, 2008 12:59 pm 
Newbie

Joined: Fri Mar 28, 2008 10:21 am
Posts: 4
the interesting thing is that when i load each individual client via hibernateTemplate.load(Client.class, id), everything works just fine: i go through all client ids, load each one and everything works as expected.

however, if i replace it with loadAll(Client.class), it fails with "collection is not associated with any session".


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 7:32 am 
Newbie

Joined: Fri Mar 28, 2008 10:21 am
Posts: 4
any takers?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 9:56 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

what is the implementation of loadAll()


Amila


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 10:48 am 
Newbie

Joined: Fri Mar 28, 2008 10:21 am
Posts: 4
amila733 wrote:
Hi

what is the implementation of loadAll()


Amila


http://springframework.cvs.sourceforge. ... iew=markup


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