我有以下设置:
现在我的文件如下:
AGENTER_LISTE.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestNhibernate
{
public class AGENTER_LISTE
{
public virtual int ID { get; set; }
public virtual String INITIALER { get; set; }
public virtual String FORNAVN { get; set; }
public virtual String EFTERNAVN { get; set; }
}
}
AGENTER_LISTE.hbm.xml:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="TestNhibernate" namespace="TestNhibernate">
<class name="TestNhibernate.AGENTER_LISTE">
<id name="ID" column="ID">
<generator class="identity" />
</id>
<property name="INITIALER" />
<property name="FORNAVN" />
<property name="Efternavn" />
</class>
</hibernate-mapping>
App.config中:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<property name="dialect">
NHibernate.Dialect.Oracle10gDialect
</property>
<property name="connection.driver_class">
NHibernate.Driver.OracleClientDriver
</property>
<property name="connection.connection_string">
Data Source=CTIR;Persist Security Info=True;User ID=*****;Password=*****;
</property>
<property name="show_sql">
true
</property>
<property name="hbm2ddl.keywords">none</property>
<mapping assembly="TestNhibernate" />
</session-factory>
</hibernate-configuration>
</configuration>
Form1.cs中:
namespace TestNhibernate
{
public partial class Form1 : Form
{
private Configuration myConfig;
private ISessionFactory mySessionFactory;
private ISession mySession;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
myConfig = new Configuration();
myConfig.Configure(); //<--- My program breaks here
mySessionFactory = myConfig.BuildSessionFactory();
mySession = mySessionFactory.OpenSession();
using (mySession.BeginTransaction())
{
AGENTER_LISTE agent = new AGENTER_LISTE {FORNAVN = "Marc", INITIALER = "MRCR212", ID = 999, EFTERNAVN = "Rasmussen" };
mySession.Save(agent);
mySession.Transaction.Commit();
}
}
}
}
有了这个我得到以下错误:
Could not compile the mapping document: TestNhibernate.AGENTER_LISTE.hbm.xml
出现以下详细错误:
NHibernate.MappingException was unhandled
Message=Could not compile the mapping document: TestNhibernate.AGENTER_LISTE.hbm.xml
Source=NHibernate
StackTrace:
at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception) in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 342
at NHibernate.Cfg.Configuration.AddDeserializedMapping(HbmMapping mappingDocument, String documentFileName) in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 530
at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc) in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 499
at NHibernate.Cfg.Configuration.ProcessMappingsQueue() in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 1865
at NHibernate.Cfg.Configuration.AddDocumentThroughQueue(NamedXmlDocument document) in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 1856
at NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader, String name) in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 1849
at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 638
at NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly) in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 676
at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly) in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 769
at NHibernate.Cfg.Configuration.AddAssembly(String assemblyName) in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 752
at NHibernate.Cfg.Configuration.DoConfigure(ISessionFactoryConfiguration factoryConfiguration) in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 1574
at NHibernate.Cfg.Configuration.Configure() in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 1433
at TestNhibernate.Form1.Form1_Load(Object sender, EventArgs e) in \\nkm18427\prv-mrcr\visual studio 2010\Projects\TestNhibernate\TestNhibernate\Form1.cs:line 29
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at TestNhibernate.Program.Main() in \\nkm18427\prv-mrcr\visual studio 2010\Projects\TestNhibernate\TestNhibernate\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: NHibernate.MappingException
Message=Problem trying to set property type by reflection
Source=NHibernate
StackTrace:
at NHibernate.Mapping.SimpleValue.SetTypeUsingReflection(String className, String propertyName, String accesorName) in p:\nhibernate-core\src\NHibernate\Mapping\SimpleValue.cs:line 359
at NHibernate.Cfg.XmlHbmBinding.PropertiesBinder.CreateProperty(IEntityPropertyMapping propertyMapping, String propertyOwnerClassName, IValue value, IDictionary`2 inheritedMetas) in p:\nhibernate-core\src\NHibernate\Cfg\XmlHbmBinding\PropertiesBinder.cs:line 399
at NHibernate.Cfg.XmlHbmBinding.PropertiesBinder.Bind(IEnumerable`1 properties, Table table, IDictionary`2 inheritedMetas, Action`1 modifier, Action`1 addToModelAction) in p:\nhibernate-core\src\NHibernate\Cfg\XmlHbmBinding\PropertiesBinder.cs:line 92
at NHibernate.Cfg.XmlHbmBinding.PropertiesBinder.Bind(IEnumerable`1 properties, IDictionary`2 inheritedMetas, Action`1 modifier) in p:\nhibernate-core\src\NHibernate\Cfg\XmlHbmBinding\PropertiesBinder.cs:line 52
at NHibernate.Cfg.XmlHbmBinding.PropertiesBinder.Bind(IEnumerable`1 properties, IDictionary`2 inheritedMetas) in p:\nhibernate-core\src\NHibernate\Cfg\XmlHbmBinding\PropertiesBinder.cs:line 47
at NHibernate.Cfg.XmlHbmBinding.RootClassBinder.Bind(HbmClass classSchema, IDictionary`2 inheritedMetas) in p:\nhibernate-core\src\NHibernate\Cfg\XmlHbmBinding\RootClassBinder.cs:line 59
at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddRootClasses(HbmClass rootClass, IDictionary`2 inheritedMetas) in p:\nhibernate-core\src\NHibernate\Cfg\XmlHbmBinding\MappingRootBinder.cs:line 83
at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddEntitiesMappings(HbmMapping mappingSchema, IDictionary`2 inheritedMetas) in p:\nhibernate-core\src\NHibernate\Cfg\XmlHbmBinding\MappingRootBinder.cs:line 42
at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind(HbmMapping mappingSchema) in p:\nhibernate-core\src\NHibernate\Cfg\XmlHbmBinding\MappingRootBinder.cs:line 29
at NHibernate.Cfg.Configuration.AddDeserializedMapping(HbmMapping mappingDocument, String documentFileName) in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 522
InnerException: NHibernate.MappingException
Message=class TestNhibernate.AGENTER_LISTE, TestNhibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null not found while looking for property: Efternavn
Source=NHibernate
StackTrace:
at NHibernate.Util.ReflectHelper.ReflectedPropertyClass(String className, String name, String accessorName) in p:\nhibernate-core\src\NHibernate\Util\ReflectHelper.cs:line 169
at NHibernate.Mapping.SimpleValue.SetTypeUsingReflection(String className, String propertyName, String accesorName) in p:\nhibernate-core\src\NHibernate\Mapping\SimpleValue.cs:line 355
InnerException: NHibernate.PropertyNotFoundException
Message=Could not find a getter for property 'Efternavn' in class 'TestNhibernate.AGENTER_LISTE'
Source=NHibernate
AccessorType=getter
PropertyName=Efternavn
StackTrace:
at NHibernate.Properties.BasicPropertyAccessor.GetGetter(Type type, String propertyName) in p:\nhibernate-core\src\NHibernate\Properties\BasicPropertyAccessor.cs:line 35
at NHibernate.Util.ReflectHelper.GetGetter(Type theClass, String propertyName, String propertyAccessorName) in p:\nhibernate-core\src\NHibernate\Util\ReflectHelper.cs:line 112
at NHibernate.Util.ReflectHelper.ReflectedPropertyClass(String className, String name, String accessorName) in p:\nhibernate-core\src\NHibernate\Util\ReflectHelper.cs:line 165
InnerException:
答案 0 :(得分:6)
错误在您的异常中声明:Message =找不到类'TestNhibernate.AGENTER_LISTE'中属性'Efternavn'的getter
这是一个不区分大小写的问题。您的房产 EFTERNAVN 是资金,但您的地图是小写 Efternawn
答案 1 :(得分:3)
将您的地图文档标记为嵌入式资源。右键单击文档,构建操作 - &gt;嵌入式资源。