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: Stored procedure -> Mapping Exception
PostPosted: Wed Sep 19, 2007 3:26 am 
Newbie

Joined: Mon Sep 17, 2007 5:01 am
Posts: 4
Hello everyone,
I've got a problem with stored procedure when I've got to set parameters, ... well I think so :D
Here is my problem:

Code:
IQuery query = (IQuery)session.GetNamedQuery("uspGetVersionFile");
query.SetParameter("FileID", id);
list = (List<VersionBackup>)query.List<VersionBackup>();


When the program reach the third line, it raises an exception as follows:

Quote:
[NHibernate.MappingException]
{"Invalid mapping information specified for type BBRestore.Models.VersionBackup, check your mapping file for property type mismatches"}


Quote:
InnerException:
InnerException {"Specified cast is not valid."}
System.Exception {System.InvalidCastException}


StackTrace:
Quote:
at NHibernate.Persister.Entity.AbstractEntityPersister.SetPropertyValues(Object obj, Object[] values)\r\n at NHibernate.Impl.SessionImpl.InitializeEntity(Object obj)\r\n at NHibernate.Loader.Loader.InitializeEntitiesAndCollections(IList hydratedObjects, Object resultSetId, ISessionImplementor session)\r\n at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)\r\n at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)\r\n at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)\r\n at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters)\r\n at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes)\r\n at NHibernate.Loader.Custom.CustomLoader.List(ISessionImplementor session, QueryParameters queryParameters)\r\n at NHibernate.Impl.SessionImpl.ListCustomQuery(ICustomQuery customQuery, QueryParameters queryParameters, IList results)\r\n at NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification spec, QueryParameters queryParameters, IList results)\r\n at NHibernate.Impl.SessionImpl.List[T](NativeSQLQuerySpecification spec, QueryParameters queryParameters)\r\n at NHibernate.Impl.SqlQueryImpl.List[T]()\r\n at BBRestore.RestoreManagement.GetVersionFiles(Int32 id) in C:\\Documents and Settings\\dde\\My Documents\\Projets\\Restore\\BBREStoreNHib\\BBRestore\\BBRestore\\RestoreManagement.cs:line 56" string



It seems to be a problem with my mapped procedure, but I can't figure out why it doesn't work. If someone see what I did wrong :)

VersionBackup.hbm.xml

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="BBRestore.Models" assembly="BBRestore">

  <class name="VersionBackup" table="Version">

    <id name="Id" column="VersionID" type="Int16">
      <generator class="identity" />
    </id>
    <property name="Version" column="Version" type="Int16" not-null="false" />
    <property name="Path" column="Path" type="String" length="2058" not-null="true"/>
    <property name="Name" column="Name" type="String" length="255" not-null="true" />
    <property name="Path" column="Path" type="String" length="2058" not-null="true"/>
    <property name="DateCreated" column="DateCreated" type="DateTime" not-null="false"/>
    <property name="LastAccess" column="LastAccess" type="DateTime" not-null="false"/>
    <property name="LastModif" column="LastModif" type="DateTime" not-null="false"/>

    <many-to-one name="DataID" class="DataBackup" column="DataID"/>
    <many-to-one name="FileID" class="FileBackup" column="FileID"/>

  </class>

  <sql-query name="uspGetVersionFile">
    <return class="BBRestore.Models.VersionBackup, BBRestore" alias="VB">
    </return>
    exec Storage.uspGetVersionFile :FileID
  </sql-query>
 
</hibernate-mapping>


VersionBackup.cs

Code:
using System;
using System.Collections.Generic;
using System.Text;

namespace BBRestore.Models
{
    public class VersionBackup
    {
        private int versionID;
        private FileBackup fileID;
        private DataBackup dataID;
        private DateTime lastAccess;
        private DateTime lastModif;
        private string name;
        private string path;
        private DateTime dateCreated;
        private int versionNum;

        public VersionBackup()
        {
        }

        public virtual int Id
        {
            get { return this.versionID; }
            set { this.versionID = value; }
        }

        public virtual FileBackup FileID
        {
            get { return this.fileID; }
            set { this.fileID = value; }
        }

        public virtual DataBackup DataID
        {
            get { return this.dataID; }
            set { this.dataID = value; }
        }

        public virtual DateTime LastAccess
        {
            get { return this.lastAccess; }
            set { this.lastAccess = value; }
        }

        public virtual DateTime LastModif
        {
            get { return this.lastModif; }
            set { this.lastModif = value;}
        }

        public virtual string Name
        {
            get { return this.name; }
            set { this.name = value; }
        }

        public virtual string Path
        {
            get { return this.path; }
            set { this.path = value; }
        }

        public virtual DateTime DateCreated
        {
            get { return this.dateCreated; }
            set { this.dateCreated = value; }
        }

        public virtual int Version
        {
            get { return this.versionNum; }
            set { this.versionNum = value; }
        }
    }
}



Hibernate version: 1.2.0

Thanks


Top
 Profile  
 
 Post subject: Invalid mapping information specified for type XXX
PostPosted: Wed Feb 27, 2008 8:06 pm 
Newbie

Joined: Wed Feb 27, 2008 7:31 pm
Posts: 2
Location: Silicon Valley, CA
I recently struggled with this same exception.

This exception originates from dynamically-generated code that Hibernate uses to populate each object from a returned row. What happens is that when the dynamically generated code has a type-casting issue, Hibernate re-throws it as a MappingException.

For me, I encountered this issue when Hibernate tried to cast an Int32 to a nullable enumeration. As I'm a novice to NHibernate, my guess is that your dynamically-generated code was trying to cast some kind of ID to a FileBackup or DateBackup object.

For someone encountering this issue, here is a debugging strategy: (YMMV)

1 - If possible, clear your database.
2 - For the table/class where this exception is occuring, insert one row with as many nulls as possible.
3 - Progressively introduce non-null values until the error occurs.

If the above steps do not work, consider temporally changing the schema/class to allow more nullable values.

I wish NHibernate's dynamically-generated code could say which property causes the casting error... It would make debugging these issues so much easier!


Top
 Profile  
 
 Post subject: Re: Stored procedure -> Mapping Exception
PostPosted: Thu Dec 17, 2009 8:22 am 
Newbie

Joined: Wed Apr 08, 2009 8:31 am
Posts: 1
I had the same problem.
The error was in hbm file. In hbm file vas
<property name="Code" column="Code" type="string" />
but real property type was int.


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.