Hi,
I have a newbie problem with many-to-many association. I have the following:
ServiceConsumer -> ConsumerWishes <- ParameterWishes
For consumers I have this part of code:
<set name="paramWishes" access="field" lazy="true" table="CONSUMERS_TO_WISHES" inverse="true" cascade="all">
<key column="CONSUMER_ID" />
<many-to-many column="WISH_ID" class="ParameterWishes" />
</set>
On the wishes part I have the following:
<set name="consumers" access="field" lazy="true" table="CONSUMERS_TO_WISHES" inverse="false" cascade="all">
<key column="WISH_ID" />
<many-to-many column="CONSUMER_ID" class="ServiceConsumer" />
</set>
I'm trying to get all consumers including all their wishes with this code:
ServiceConsumer consumer = consumerDAO.GetById(serviceConsumer.Id);
public virtual T GetById(ID id)
{
T t = default(T);
t = (T)Session.Get(_typeClass, id);
return t;
}
or this code:
ServiceConsumer consumer = consumerDAO.GetByName(serviceConsumer.Name);
public ServiceConsumer GetByName(string name)
{
return Session.CreateQuery("from ServiceConsumer sc where sc.Name = :Name").SetString("Name", name).UniqueResult<ServiceConsumer>();
}
Both of these methods fetch just first N of the wishes, but not all of them. I've tried to put fetch="join" instead of lazy="true", but it didn't help. Any thoughts?
Thanks.