我不知道錯誤在哪裏。NHibernate無法編譯映射
我使用NHibernate C#並將程序集追加到配置中。 問題NHibernateException:無法編譯映射Note.hbm.xml
public static class NHibernateHelper
{
private static Configuration _cfg;
private static ISessionFactory _sessionFactory;
private static ISessionFactory SessionFactory {
get {
if (_sessionFactory == null) {
_cfg = new Configuration();
_cfg.Configure();
_cfg.AddAssembly(typeof(User).Assembly);
_cfg.AddAssembly(typeof(Changelog).Assembly);
_cfg.AddAssembly(typeof(Note).Assembly);
_sessionFactory = _cfg.BuildSessionFactory();
}
return _sessionFactory;
}
}
public static ISession OpenSession() {
return SessionFactory.OpenSession();
}
public static void DatabaseSchemaLoader() {
ISession session = OpenSession();
new SchemaExport(_cfg).Create(true, true);
session.Close();
}
}
我的筆記類是shared.data.content
namespace CRMSystem.shared.data.content
{
public class Note
{
public virtual int id { get; set; }
public virtual string title{ get; set;}
public virtual string text { get; set; }
public virtual int priority { get; set; }
public virtual long createdTime { get; set; }
public virtual long lastEditTime { get; set; }
}
}
Note.hbm.xml(集生成操作:嵌入的資源,複製到輸出:複製總是)
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="CRMSystem"
namespace="CRMSystem.shared.data.content">
<class name="Note" table="`Note`" lazy="false">
<id name="id" column="`id`" type="int">
<generator class="identity"></generator>
</id>
<property name="title" column="`title`" type="String"/>
<property name="text" column="`text`" type="String" />
<property name="priority" column="`priority`" type="int" />
<property name="createdTime" column="`createdTime`" type="long" />
<property name="lastEditTime" column="`lastEditTime`" type="long" />
</class>
</hibernate-mapping>
感謝您的回答。
我今天在很多方面嘗試,發現它的工作原理:
_cfg.Configure();
_cfg.AddAssembly(typeof(User).Assembly);
//_cfg.AddAssembly(typeof(Changelog).Assembly);
//_cfg.AddAssembly(typeof(Note).Assembly);
當我補充說:(任何級別)
_cfg.AddAssembly(typeof(Changelog).Assembly);
每次我得到一個錯誤:無法編譯註意事項.hbm.xml 我可以保存到數據庫的每個類(用戶,更新日誌,注意)。 我無法解釋。
有沒有人有這種情況?
完全例外:
NHibernate.MappingException: Could not compile the mapping document: CRMSystem.shared.data.mapping.Note.hbm.xml ---> NHibernate.DuplicateMappingException: Duplicate class/entity mapping CRMSystem.shared.data.content.Note
w NHibernate.Cfg.Mappings.AddClass(PersistentClass persistentClass)
w NHibernate.Cfg.XmlHbmBinding.RootClassBinder.Bind(HbmClass classSchema, IDictionary`2 inheritedMetas)
w NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddRootClasses(HbmClass rootClass, IDictionary`2 inheritedMetas)
w NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddEntitiesMappings(HbmMapping mappingSchema, IDictionary`2 inheritedMetas)
w NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind(HbmMapping mappingSchema)
w NHibernate.Cfg.Configuration.AddDeserializedMapping(HbmMapping mappingDocument, String documentFileName)
--- Koniec śladu stosu wyjątków wewnętrznych ---
w NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)
w NHibernate.Cfg.Configuration.AddDeserializedMapping(HbmMapping mappingDocument, String documentFileName)
w NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)
w NHibernate.Cfg.Configuration.ProcessMappingsQueue()
w NHibernate.Cfg.Configuration.AddDocumentThroughQueue(NamedXmlDocument document)
w NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader, String name)
w NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name)
w NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly)
w NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly)
當我沒有什麼補充,我得到異常:沒有留存
可能會刪除列屬性Note.hbm.xml中的單個線索 – DanielVorph
首先 - 將您的答案移動到您的問題中。刪除該答案。其次,你還可以附加完整的內部異常堆棧嗎?像我一樣?將會有明確的答案 –
您能否顯示**完整**異常?確切地說,在您引用後*無法編譯Note.hbm.xml * - 確切地說,下一行清楚地說明了問題所在。觀察我自己的答案,你會看到我爲你創造的這種提取物...... –