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.  [ 1 post ] 
Author Message
 Post subject: Resolving interface types
PostPosted: Fri Apr 25, 2008 8:20 am 
Newbie

Joined: Tue Apr 22, 2008 7:17 am
Posts: 14
Hi,

I have an interface IRatingScale which is implemented by a concrete class RatingScale. My mapping file is defined in terms of RatingScale. I have a generic repository class GenericRepository<T> which implements IRepository<T>, which defines (among others) two methods as wrappers around ISession's Get<T> and CreateCriteria as follows:

Code:

        public T GetById(IdT id)
        {
            return _sessionManager.OpenSession().Get<T>(id);
        }


        public ICollection<T> FindAll(params ICriterion[] criteria)
        {
            ICriteria crit = _sessionManager.OpenSession().CreateCriteria(typeof(T));
            foreach (ICriterion criterion in criteria)
            {
                //allow some fancy antics like returning possible return
                // or null to ignore the criteria
                if (criterion == null)
                    continue;
                crit.Add(criterion);
            }
            return crit.List<T>();
        }


In a client class I have a IRepository defined as IRepository<IRatingScale> (mostly so I am able to unit test the client class) which is injected with a GenericReposity<IRatingScale>.

The issue I'm having is that the FindAll method is somehow able to resolve the fact that it needs to use the RatingScale mapping even tho T is defined as an IRatingScale, but Get<T> can't and throws a mapping exception.

My mapping file is below:

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                  assembly="OzoneHR.Domain"
                  namespace="OzoneHR.Domain.RatingScale">
  <class name="RatingScale" table="RatingScale">
    <id name="Id" access="nosetter.camelcase-underscore"
        column="RatingScaleID" type="Int32">
      <generator class="identity" />
    </id>
    <property name="RatingScaleName" column="RatingScaleName" type="String" not-null="true" access="nosetter.camelcase-underscore" />
    <list name="Ratings"
         table="Rating"
         cascade="all"
         access="nosetter.camelcase-underscore"
         >
      <key column="RatingScaleID" />
      <index column="ScalePosition" type="Int32" />
      <composite-element class="Rating">
        <property name="Name" access="nosetter.camelcase-underscore" column="RatingName" not-null="true" />
        <property name="ShortName" access="nosetter.camelcase-underscore" column="ShortName" not-null="true" />
        <property name="Description" access="nosetter.camelcase-underscore" column="Description" not-null="true" />
      </composite-element>
    </list>
  </class>
</hibernate-mapping>


I can't define my mapping in terms of class=IRating, as the Ratings list on RatingScale is defined as an internal protected property i.e. clients of the class shouldn't see it.

Any ideas on how I can workaround this problem?

Thanks,
Matt


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.