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.