2010-08-31 3 views
0

erreur Impossible de compiler le document de mapping: WebApplication1.documents.hbm.xml [alt texte] [1]NHibernate + asp.net

photo http://forum.sources.ru/index.php?act=Attach&type=post&id=2684138&attach_id=1097

web .config

<?xml version="1.0"?> 
<configuration> 
    <configSections> 
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /> 
     <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
      <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
       <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
       <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
        <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/> 
        <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
        <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
        <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
       </sectionGroup> 
      </sectionGroup> 
     </sectionGroup> 
    </configSections> 

    <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> 
    <session-factory> 
     <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property> 
     <property name="connection.provider"> 
     NHibernate.Connection.DriverConnectionProvider 
     </property> 
     <property name="connection.driver_class"> 
     NHibernate.Driver.SqlClientDriver 
     </property> 
     <property name="connection.connection_string"> 
     Data Source=MICROSOF-993CA1\SQLEXPRESS;Initial Catalog=DocsContainer;Persist Security Info=True;User ID=sa;Password=123 
     </property> 
     <property name="dialect"> 
     NHibernate.Dialect.MsSql2005Dialect 
     </property> 
     <property name="show_sql"> 
     false 
     </property> 
    </session-factory> 
    <mapping resource="NHibernate_1.Book.hbm.xml" assembly="NHibernate_1" /> 
    </hibernate-configuration> 
    <appSettings/> 
    <connectionStrings/> 

    <system.web> 
     <!-- 
      Значение параметра compilation debug="true" означает, что в компилированную страницу будут вставлены 
      отладочные символы. Так как этот 
      параметр влияет на производительность, следует задавать для него значение True 
      только на этапе разработки. 
     --> 
     <compilation debug="true"> 
      <assemblies> 
       <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> 
       <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> 
       <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
       <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> 
      </assemblies> 
     </compilation> 
     <!-- 
      Раздел <authentication> позволяет настроить параметры 
      режима проверки подлинности, используемого ASP.NET для проверки 
      подлинности пользователя, запрашивающего разрешение на доступ. 
     --> 


     <authentication mode="Forms"> 

     <forms name="ASP_XML_Form" loginUrl="login.aspx" protection="All" timeout="30" path="/" requireSSL="false" slidingExpiration="true"/> 

    </authentication> 
     <!-- 
      Раздел <customErrors> позволяет настраивать 
      параметры действий на случай возникновения необработанных ошибок 
      во время выполнения запроса. А именно, 
      он позволяет разработчикам настраивать HTML-страницы 
      с сообщениями об ошибках, которые будут отображаться вместо трассировки стека ошибок. 

     <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> 
      <error statusCode="403" redirect="NoAccess.htm" /> 
      <error statusCode="404" redirect="FileNotFound.htm" /> 
     </customErrors> 
     --> 
     <pages> 
      <controls> 
       <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
       <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
      </controls> 
     </pages> 
     <httpHandlers> 
      <remove verb="*" path="*.asmx"/> 
      <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
      <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
      <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/> 
     </httpHandlers> 
     <httpModules> 
      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
     </httpModules> 
    </system.web> 
    <system.codedom> 
     <compilers> 
      <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> 
       <providerOption name="CompilerVersion" value="v3.5"/> 
       <providerOption name="WarnAsError" value="false"/> 
      </compiler> 
     </compilers> 
    </system.codedom> 
    <!-- 
     Раздел system.webServer требуется для работы ASP.NET AJAX в 
     Internet Information Services 7.0. Он не требуется для более ранней версии IIS. 
    --> 
    <system.webServer> 
     <validation validateIntegratedModeConfiguration="false"/> 
     <modules> 
      <remove name="ScriptModule"/> 
      <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
     </modules> 
     <handlers> 
      <remove name="WebServiceHandlerFactory-Integrated"/> 
      <remove name="ScriptHandlerFactory"/> 
      <remove name="ScriptHandlerFactoryAppServices"/> 
      <remove name="ScriptResource"/> 
      <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
      <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
      <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
     </handlers> 
    </system.webServer> 
    <runtime> 
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
      <dependentAssembly> 
       <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/> 
       <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/> 
      </dependentAssembly> 
      <dependentAssembly> 
       <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/> 
       <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/> 
      </dependentAssembly> 
     </assemblyBinding> 
    </runtime> 
</configuration> 

documents.hbm.xml

<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true" namespace="WebApplication1" assembly="WebApplication1"> 
    <class name="WebApplication1.documents" table="documents" lazy="false"> 
    <id name="id" access="field"> 
     <generator class="native" /> 
    </id> 
    <property name="name" access="field" column="name"/> 
    <property name="date" access="field" column="date"/> 
    <property name="author" access="field" column="author"/> 
    <property name="doclink" access="field" column="doclink"/> 
    </class> 
</hibernate-mapping> 

documents.cs

using System; 
using System.Collections; 
using System.Data; 
using System.Linq; 
using System.Reflection; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Xml.Linq; 
using NHibernate; 
using System.Security.Principal; 
using NHibernate.Cfg; 


namespace WebApplication1 
{ 
    public class documents 
    { 
      public int id; 
      public string name; 
      public DateTime date; 
      public string doclink; 
      public documents manager; 

      public void CreateDocuments() 
      { 
       documents exSample = new documents(); 
       exSample.name = "never"; 

       using (ISession session = OpenSession()) 
       { 
        using (ITransaction transaction = session.BeginTransaction()) 
        { 
         session.Save(exSample); 
         transaction.Commit(); 
        } 
         //Response.Write("saved exSample to the databases"); 
       } 
      } 

      public ISessionFactory factory; 

      public ISession OpenSession() 
      { 
       if (factory == null) 
       { 
        Configuration conf = new Configuration(); 
        conf.AddAssembly(Assembly.GetCallingAssembly()); 
        factory = conf.BuildSessionFactory(); 
       } 
       return factory.OpenSession(); 
      } 
    } 
} 

utilisation

documents doc = nouveaux documents(); doc.CreateDocuments();

dans

doc.aspx.cs

using System; 
using System.Collections; 
using System.Configuration; 
using System.Data; 
using System.Linq; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Xml.Linq; 

namespace WebApplication1 
{ 
    public partial class docs : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 
      if (!Request.IsAuthenticated) 
      { 
       Response.Redirect("login.aspx"); 
      } 

     } 

     protected void TextBox1_TextChanged(object sender, EventArgs e) 
     { 

     } 

     protected void Button1_Click(object sender, EventArgs e) 
     { 
      /* String rootPath = Server.MapPath("docs\\"); 

      if (FileUpload1.HasFile) 
      { 
       FileUpload1.SaveAs(rootPath + FileUpload1.FileName); 
       Response.Write("file save in " + rootPath+FileUpload1.FileName + " size of file " + FileUpload1.FileBytes.Length.ToString()); 
      } 
      */ 
      documents doc = new documents(); 
      doc.CreateDocuments(); 
     } 
    } 
} 

base Date

CREATE TABLE documents(
    id int identity PRIMARY KEY, 
    name nvarchar(50), 
    date datetime, 
author nvarchar(50), 
doclink nvarchar(50) 
) 

NHibernate.MappingException не обработано пользовательским ко дом
Message = "Impossible de compiler le mappage document: WebApplication1.documents.hbm.xml"
Source = "NHibernate" StackTrace: в NHibernate.Cfg.Configuration.LogAndThrow (Exception exception) в NHibernate. Cfg.Configuration.AddValidatedDocument (NamedXmlDocument doc) в NHibernate.Cfg.Configuration.ProcessMappingsQueue() в NHibernate.Cfg.Configuration.AddDocumentThroughQueue (NamedXmlDocument document) в NHibernate.Cfg.Configuration.AddXmlReader (XmlReader hbmReader, String nom) NHibernate.Cfg.Configuration.AddInputStream (courant xmlInputStream, String name) в NHibernate.Cfg.Configuration.AddResource (String path , l'assemblage de montage) в NHibernate.Cfg.Configuration.AddAssembly (assemblée de montage ) в WebApplication1. documents.OpenSession() в D: \ Documents and Settings \ admin \ Мои документы \ Visual studio 2008 \ Projects \ WebApplication1 \ WebApplication1 \ documents.cs: строка в WebApplication1.documents.CreateDocuments() в D : \ Documents and Settings \ Admin \ Мои документы \ Visual Studio 2008 \ Proj ects \ WebApplication1 \ WebApplication1 \ documents.cs: строка в WebApplication1.docs.Button1_Click (Object expéditeur, EventArgs e) в D: \ Documents and Settings \ Admin \ Мои документы \ Visual Studio 2008 \ Projects \ WebApplication1 \ WebApplication1 \ docs.aspx.cs: строка в System.Web. UI.WebControls.Button.OnClick (EventArgs e) в System.Web.UI.WebControls.Button.RaisePostBackEvent (String eventArgument) в System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler. RaisePostBackEvent (String eventArgument) dans System.Web.UI.Page.RaisePostBackEvent (IPostBackEventHandler sourceControl, String eventArgument) System.Web.UI.Page.RaisePostBackEvent (NameValueCollection postData) в System.Web.UI.Page.ProcessRequestMain (Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException: NHibernate.MappingException Message = "Problème d'essayer de définir type de propriété par la réflexion » Source = "NHibernate" StackTrace: в NHibernate.Mapping.SimpleValue.SetTypeUsingReflection (String className , String propertyName, String accesorName) в NHibernate.Cfg.XmlHbmBinding.ClassBinder.CreateProperty (iValue valeur , String propertyName, String className , XmlNode sous-noeud, IDictionary 2 inheritedMetas) в NHibernate.Cfg.XmlHbmBinding.ClassBinder.PropertiesFromXML(XmlNode node, PersistentClass model, IDictionary 2 inheritedMetas, UniqueKey UniqueKey, Boolean mutable, nullable Boolean, Boolean naturalId) в NHibernate.Cfg.XmlHbmBinding.ClassBinder.PropertiesFromXML (noeud XmlNode , modèle PersistentClass, IDictionary 2 inheritedMetas) в NHibernate.Cfg.XmlHbmBinding.RootClassBinder.Bind(XmlNode node, HbmClass classSchema, IDictionary 2 inheritedMetas) в NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddRootClasses (XmlNode parentNode, IDictionary`2 inheritedMetas) в NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind (XmlNode noeud) в NHibernate.Cfg. Configuration.Ad dValidatedDocument (NamedXmlDocument doc) InnerException: NHibernate.MappingException message = "WebApplication1.documents de classe, WebApplication1, Version = 1.0.0.0, Culture = neutral , PublicKeyToken = null pas trouvé tout en regardant la propriété: auteur" Source = "NHibernate" StackTrace: в NHibernate.Util.ReflectHelper.ReflectedPropertyClass (String className , String name, String accessorName) в NHibernate.Mapping.SimpleValue.SetTypeUsingReflection (String className , String propertyName, String accesorName) InnerException: NHibernate.PropertyNotFoundException Message = "Impossible de trouver l'auteur" champ dans la classe 'WebApplication1.documents'" Source = "NHibernate" PropertyName = "author" StackTrace: в NHibernate.Properties.FieldAccessor.GetField (Type Type , String fieldName, type originalType) в NHibernate.Properties.FieldAccessor.GetField (Type de type , String fieldName, type originalType) в NHibernate.Properties.FieldAccessor.GetField (Type Type , String fieldName) dans NHibernate.Properties. FieldAccessor.GetGetter (Type theClass, String propertyName) в NHibernate.Util.ReflectHelper.GetGetter (Type theClass, String propertyName, String propertyAccessorName) в NHibernate.Util.ReflectHelper.ReflectedPropertyClass (String className , String name, String accessorName) InnerException:

+0

Quelle est l'exception interne? –

Répondre

3

NHibernate ne pense pas que votre document de cartographie peut être appliquée à votre classe.

Sans voir l'exception, je peux voir à partir de votre code que la classe documents manque une propriété d'auteur qui est mentionnée dans le document de mappage.

+0

En raison de votre réponse, j'ai réalisé que j'avais un nom de propriété qui ne correspondait pas, alors merci de résoudre mon problème 3 ans plus tard! – Keven

+0

@Keven - ne me remerciez pas, merci Stackoverflow pour avoir rendu possible tout ce partage de connaissances! –