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