Hello,
I use polymorphic associations with the <any> keyword.
This association gathers several classes with all the same properties.
I'm trying to perform a query on this association and I receive the error described below.
Is <any> association the correct way to perform polymorphic association ?
How to perform a query on this kind of association?
Thanks in advance,
David
NHibernate version: 1.01
Mapping documents:
Code:
...
<any id-type="String" meta-type="String" name="Meterable" access="property">
<meta-value value="Connection" class="Cc.Core.DomainModel.Connection, CCCoreRDM.Net" />
<meta-value value="ConnectionPoint" class="Cc.Core.DomainModel.ConnectionPoint, CCCoreRDM.Net" />
<meta-value value="GlobalConnection" class="Cc.Core.DomainModel.GlobalConnection, CCCoreRDM.Net" />
<meta-value value="MeteringPoint" class="Cc.Core.DomainModel.MeteringPoint, CCCoreRDM.Net" />
<meta-value value="DGOConnection" class="Cc.Core.DomainModel.DGOConnection, CCCoreRDM.Net" />
<meta-value value="DGOConnectionPoint" class="Cc.Core.DomainModel.DGOConnectionPoint, CCCoreRDM.Net" />
<column name="meterableClass" not-null="true" />
<column name="meterableId" not-null="true" />
</any>
...
Query code : Code:
ICriteria crit=CCContext.Current.NHibernateSession.CreateCriteria(typeof(DomainModel.MeteringRight));
crit.CreateCriteria("Meterable").Add(Expression.Eq("Id",meterableId));
return crit.List();
Full stack trace of any exception that occurs:
Quote:
--- End of inner exception stack trace (any types do not have a unique referenced persister) ---
at Cc.Core.Bo.MeteringRight.query(SMetRightQuery rqst) in c:\projects\cc\corer\cccorerlib.net\bo\meteringright.cs:line 312
at Cc.Core.Bo.MeteringRight._query(SMetRightQuery rqst) in c:\projects\cc\corer\cccorerlib.net\bo\meteringright.cs:line 83
at Cc.Core.DomainModel.MeteringRight.Query(String contractId, String availabilityData, String availabilityPeriod, String rightType, String meterableId, String meterableClass, XsDateTime beginDate, XsDateTime endDate) in c:\projects\cc\corer\cccorerdm.net\domainmodel\meteringright.cs:line 128
at NHibernate.Impl.CriteriaImpl.CreateCriteria(String associationPath)
at NHibernate.Impl.CriteriaImpl.CreateCriteriaAt(String rootAlias, String associationPath)
at NHibernate.Impl.CriteriaImpl.CreateCriteriaAt(String rootAlias, String associationPath, String alias)
at NHibernate.Impl.CriteriaImpl.CreateAlias(String rootAlias, String associationPath, String alias)
at NHibernate.Impl.CriteriaImpl.GetClassForPath(String rootAlias, String associationPath)
at NHibernate.Type.ObjectType.GetAssociatedClass(ISessionFactoryImplementor factory)]