views:

41

answers:

1

error Could not compile the mapping document: WebApplication1.documents.hbm.xml ![alt text][1]

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();
            }
    }
}

use

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

in

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();
        }
    }
}

date base

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

NHibernate.MappingException не обработано пользовательским кодом
Message="Could not compile the mapping 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 name) в NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) в NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly) в NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly) в WebApplication1.documents.OpenSession() в D:\Documents and Settings\Admin\Мои документы\Visual Studio 2008\Projects\WebApplication1\WebApplication1\documents.cs:строка 51 в WebApplication1.documents.CreateDocuments() в D:\Documents and Settings\Admin\Мои документы\Visual Studio 2008\Projects\WebApplication1\WebApplication1\documents.cs:строка 33 в WebApplication1.docs.Button1_Click(Object sender, EventArgs e) в D:\Documents and Settings\Admin\Мои документы\Visual Studio 2008\Projects\WebApplication1\WebApplication1\docs.aspx.cs:строка 43 в 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) в 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="Problem trying to set property type by reflection" Source="NHibernate" StackTrace: в NHibernate.Mapping.SimpleValue.SetTypeUsingReflection(String className, String propertyName, String accesorName) в NHibernate.Cfg.XmlHbmBinding.ClassBinder.CreateProperty(IValue value, String propertyName, String className, XmlNode subnode, IDictionary2 inheritedMetas) в NHibernate.Cfg.XmlHbmBinding.ClassBinder.PropertiesFromXML(XmlNode node, PersistentClass model, IDictionary2 inheritedMetas, UniqueKey uniqueKey, Boolean mutable, Boolean nullable, Boolean naturalId) в NHibernate.Cfg.XmlHbmBinding.ClassBinder.PropertiesFromXML(XmlNode node, PersistentClass model, IDictionary2 inheritedMetas) в NHibernate.Cfg.XmlHbmBinding.RootClassBinder.Bind(XmlNode node, HbmClass classSchema, IDictionary2 inheritedMetas) в NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddRootClasses(XmlNode parentNode, IDictionary`2 inheritedMetas) в NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind(XmlNode node) в NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc) InnerException: NHibernate.MappingException Message="class WebApplication1.documents, WebApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null not found while looking for property: author" 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="Could not find field 'author' in class 'WebApplication1.documents'" Source="NHibernate" PropertyName="author" StackTrace: в NHibernate.Properties.FieldAccessor.GetField(Type type, String fieldName, Type originalType) в NHibernate.Properties.FieldAccessor.GetField(Type type, String fieldName, Type originalType) в NHibernate.Properties.FieldAccessor.GetField(Type type, String fieldName) в 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:

+2  A: 

NHibernate does not think that Your mapping document can be applied to Your class.

Without seeing the exception, I can see from Your code that the documents class is missing an author property that is mentioned in the mapping document.

Andreas Paulsson