Hi all,
This post accurately describes the problems I am having
http://forum.hibernate.org/viewtopic.php?t=977139&highlight=cproxy
I have an object contact that has four many-to-one relationships. If these associated objects are in the session cache then I am in trouble.
I need these associated objects to be not proxies.
To cut a long story short, I need to somehow initialize the contact and all it’s associated objects.
Is there a short way of doing this, I have resorted to creating a multi part query each time I want to load a contact like so:
Code:
ISession session = _sessionManager.OpenSession();
IQuery contactQuery = session.CreateQuery("from Contact c where c.Uid = :contactuid");
contactQuery.SetGuid("contactuid", contactUid);
string hql = "select co.Company from Contact co where co.Uid = :comanycontactuid";
IQuery companyQuery = session.CreateQuery(hql);
companyQuery.SetGuid("comanycontactuid", contactUid);
IQuery businessUnitQuery =
session.CreateQuery("select co.BusinessUnit from Contact co where co.Uid = :businessunituid");
businessUnitQuery.SetGuid("businessunituid", contactUid);
IQuery siteQuery = session.CreateQuery("select co.Site from Contact co where co.Uid = :siteuid");
siteQuery.SetGuid("siteuid", contactUid);
IQuery businessFunctionQuery = session.CreateQuery("select co.BusinessFunction from Contact co where co.Uid = :bfcontactuid");
businessFunctionQuery.SetGuid("bfcontactuid", contactUid);
IList results = session.CreateMultiQuery()
.Add(contactQuery)
.Add(companyQuery)
.Add(businessUnitQuery)
.Add(siteQuery)
.Add(businessFunctionQuery)
.List();
Contact ret = ObjectFromArrayList<Contact>(results[0]);
ret.Company = ObjectFromArrayList<Company>(results[1]);
ret.BusinessUnit = ObjectFromArrayList<BusinessUnit>(results[2]);
ret.Site = ObjectFromArrayList<Site>(results[3]);
ret.BusinessFunction = ObjectFromArrayList<BusinessFunction>(results[4]);
return ret;
Surely there has to be a better way than this?
Cheers