-->
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.  [ 3 posts ] 
Author Message
 Post subject: Query on polymorphic associations
PostPosted: Tue Jan 24, 2006 12:19 pm 
Newbie

Joined: Wed Aug 31, 2005 8:23 am
Posts: 5
Location: Belgium
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)]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 3:00 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Try using lowercase "id" property name instead of "Id".


Top
 Profile  
 
 Post subject: Any other idea...
PostPosted: Wed Jan 25, 2006 5:14 am 
Newbie

Joined: Wed Aug 31, 2005 8:23 am
Posts: 5
Location: Belgium
Thank you sergey... Unfortunately It doesn't work.

All my objects ids are stored in a property like :
Code:
      [Id(0,Access="property",Name="Id")]
      [Generator(1,Class="assigned")]
      public string Id
      {
         get
         {
            return _id;
         }
         set
         {
            _id = value;
         }
      }


Therefore, I think that "Id" with the "I" in uppercase is correct.
Do you have any other ideas about my problem?
Is it better to use <union-subclass> instead of <any> for a polymorphic association?


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