-->
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.  [ 6 posts ] 
Author Message
 Post subject: Criteria problem: could not resolve property
PostPosted: Sun Jul 01, 2007 11:50 am 
Newbie

Joined: Tue Feb 20, 2007 12:04 pm
Posts: 16
I'm running into a really weird problem using Criteria to make a really simple query of a table, and am starting to wonder if this is a bug.

For starters, Criteria works fine without any expression. For example:
Code:
IList songList = session.CreateCriteria(typeof(SongType)).List();


...works perfectly fine. However, if I add criteria into the mix:

Code:
IList songList = session.CreateCriteria(typeof(SongType))                        .Add(NHibernate.Expression.Property.ForName("Artist").Like("botti",MatchMode.Anywhere))
.List();


...I get the following exception:
Code:
Failure could not resolve property: Artist of: com.brightharbour.schema.SongProviderType


For whatever reason, NHibernate get confused when it attempts to resolve properties. Here's my mapping files:

SongType
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">
  <class name="com.brightharbour.schema.SongType, BH.Service" table="Songs" lazy="false">
    <id name="MediaKey" column="MediaKey" type="String">
      <generator class="assigned" />
    </id>   
    <property name="Title" type="String"/>
    <property name="Artist" type="String"/>
    <property name="Album" type="String"/>
    <property name="Genre" type="String"/>
    <property name="Description" type="String"/>
    <property name="Duration" type="String"/>
    <property name="Publisher" type="String"/>
    <property name="Copyright" type="String"/>
    <property name="Thumbnail" type="String"/>
    <property name="Hits" type="Int32"/>
    <property name="Tags" type="String"/>
  </class>
</hibernate-mapping>


SongProviderType
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">
  <class name="com.brightharbour.schema.SongProviderType, BH.Service" table="ProviderSongs" lazy="false">
    <id name="MediaPrimaryKey" column="MediaPrimaryKey" type="Int32">
      <generator class="identity" />
    </id>
    <property name="MediaKey" type="String" />
    <property name="MediaId" type="String" />
    <property name="MimeType" type="String"/>
    <property name="SourceUrl" type="String"/>
  </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 01, 2007 1:44 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Why does the exception mention SongProviderType if the criteria you are trying to make work does not make any use of SongProviderType?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 01, 2007 3:02 pm 
Newbie

Joined: Tue Feb 20, 2007 12:04 pm
Posts: 16
That's a really good question -- no clue. SongProviderType extends SongType, but I really have no idea why it would be getting confused. Here's the relationship in schema:

Code:
  <xs:complexType name="MediaType">
    <xs:sequence>
      <xs:element name="MediaPrimaryKey" type="xs:int" />
      <xs:element name="MediaKey" type="xs:string" />
      <xs:element name="Title" type="xs:string" />
      <xs:element name="Description" type="xs:string" />
      <xs:element name="Duration" type="xs:string" />
      <xs:element name="Publisher" type="xs:string" />
      <xs:element name="Copyright" type="xs:string" />
      <xs:element name="Thumbnail" type="ThumbnailType" />
      <xs:element name="Rating" type="RatingType" />
      <xs:element name="Hits" type="xs:int" />
      <xs:element name="Tags" type="xs:string" />
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="SongType">
    <xs:complexContent>
      <xs:extension base="MediaType">
        <xs:sequence>
          <xs:element name="Artist" type="xs:string" />
          <xs:element name="Album" type="xs:string" />
          <xs:element name="Genre" type="xs:string" />
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  <xs:complexType name="SongProviderType">
    <xs:complexContent>
      <xs:extension base="SongType">
        <xs:sequence>
          <xs:element name="MediaProvider" type="MediaProviderEnum" />
          <xs:element name="ProviderId" type="xs:string" />
          <xs:element name="MediaId" type="xs:string" />
          <xs:element name="SourceUrl" type="xs:string" />
          <xs:element name="MimeType" type="xs:string" />
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 02, 2007 10:41 am 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
Something is fishy with the way that you implemented inheritance for these. Not sure what relevance the XSL is supposed to provide...could you give some class code and ddl, and perhaps how you approached the inheritance mapping for these?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 02, 2007 10:54 am 
Newbie

Joined: Tue Feb 20, 2007 12:04 pm
Posts: 16
Sorry -- that's not XSL, but XSD, which represents the relationship model that I use to generate classes. I use schema-tools to auto-generate my classes:

Here's the resultant classes (sub-types not shown for brevity):

MediaType
Code:
/// <remarks/>
    [System.Xml.Serialization.XmlIncludeAttribute(typeof(SongType))]
    [System.Xml.Serialization.XmlIncludeAttribute(typeof(SongProviderType))]
    [System.Xml.Serialization.XmlIncludeAttribute(typeof(VideoType))]
    [System.Xml.Serialization.XmlIncludeAttribute(typeof(VideoProviderType))]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:com.brightharbour.schema")]
    public partial class MediaType {
       
        private int mediaPrimaryKeyField;
       
        private string mediaKeyField;
       
        private string titleField;
       
        private string descriptionField;
       
        private string durationField;
       
        private string publisherField;
       
        private string copyrightField;
       
        private ThumbnailType thumbnailField;
       
        private RatingType ratingField;
       
        private int hitsField;
       
        private string tagsField;
       
        /// <remarks/>
        public int MediaPrimaryKey {
            get {
                return this.mediaPrimaryKeyField;
            }
            set {
                this.mediaPrimaryKeyField = value;
            }
        }
       
        /// <remarks/>
        public string MediaKey {
            get {
                return this.mediaKeyField;
            }
            set {
                this.mediaKeyField = value;
            }
        }
       
        /// <remarks/>
        public string Title {
            get {
                return this.titleField;
            }
            set {
                this.titleField = value;
            }
        }
       
        /// <remarks/>
        public string Description {
            get {
                return this.descriptionField;
            }
            set {
                this.descriptionField = value;
            }
        }
       
        /// <remarks/>
        public string Duration {
            get {
                return this.durationField;
            }
            set {
                this.durationField = value;
            }
        }
       
        /// <remarks/>
        public string Publisher {
            get {
                return this.publisherField;
            }
            set {
                this.publisherField = value;
            }
        }
       
        /// <remarks/>
        public string Copyright {
            get {
                return this.copyrightField;
            }
            set {
                this.copyrightField = value;
            }
        }
       
        /// <remarks/>
        public ThumbnailType Thumbnail {
            get {
                return this.thumbnailField;
            }
            set {
                this.thumbnailField = value;
            }
        }
       
        /// <remarks/>
        public RatingType Rating {
            get {
                return this.ratingField;
            }
            set {
                this.ratingField = value;
            }
        }
       
        /// <remarks/>
        public int Hits {
            get {
                return this.hitsField;
            }
            set {
                this.hitsField = value;
            }
        }
       
        /// <remarks/>
        public string Tags {
            get {
                return this.tagsField;
            }
            set {
                this.tagsField = value;
            }
        }
    }


SongType
Code:
/// <remarks/>
    [System.Xml.Serialization.XmlIncludeAttribute(typeof(SongProviderType))]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:com.brightharbour.schema")]
    public partial class SongType : MediaType {
       
        private string artistField;
       
        private string albumField;
       
        private string genreField;
       
        /// <remarks/>
        public string Artist {
            get {
                return this.artistField;
            }
            set {
                this.artistField = value;
            }
        }
       
        /// <remarks/>
        public string Album {
            get {
                return this.albumField;
            }
            set {
                this.albumField = value;
            }
        }
       
        /// <remarks/>
        public string Genre {
            get {
                return this.genreField;
            }
            set {
                this.genreField = value;
            }
        }
    }



SongProviderType
Code:
/// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:com.brightharbour.schema")]
    public partial class SongProviderType : SongType {
       
        private MediaProviderEnum mediaProviderField;
       
        private string providerIdField;
       
        private string mediaIdField;
       
        private string sourceUrlField;
       
        private string mimeTypeField;
       
        /// <remarks/>
        public MediaProviderEnum MediaProvider {
            get {
                return this.mediaProviderField;
            }
            set {
                this.mediaProviderField = value;
            }
        }
       
        /// <remarks/>
        public string ProviderId {
            get {
                return this.providerIdField;
            }
            set {
                this.providerIdField = value;
            }
        }
       
        /// <remarks/>
        public string MediaId {
            get {
                return this.mediaIdField;
            }
            set {
                this.mediaIdField = value;
            }
        }
       
        /// <remarks/>
        public string SourceUrl {
            get {
                return this.sourceUrlField;
            }
            set {
                this.sourceUrlField = value;
            }
        }
       
        /// <remarks/>
        public string MimeType {
            get {
                return this.mimeTypeField;
            }
            set {
                this.mimeTypeField = value;
            }
        }
    }


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 02, 2007 2:46 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
adkent wrote:
Sorry -- that's not XSL, but XSD


That's the problem with acronyms--one small typo gives you a whole different concept.

It is unclear from your mappings what your inhertiance strategy is. You've either incorrectly used Table per Concrete Class or Table per Subclass for inheritance.

I'd study this.


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