development

NHibernate.MappingException : XYZ에 대한 지속 자 없음

big-blog 2020. 7. 1. 07:35
반응형

NHibernate.MappingException : XYZ에 대한 지속 자 없음


이제, 당신이 말을하기 전에 : 내가 했던 구글 내 hbm.xml파일 입니다 포함 리소스.

다음은 내가 호출하는 코드입니다.

ISession session = GetCurrentSession();
var returnObject =  session.Get<T>(Id);

클래스에 대한 내 매핑 파일은 다음과 같습니다.

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="HQData.Objects.SubCategory, HQData" table="SubCategory" lazy="true">
    <id name="ID" column="ID" unsaved-value="0">
      <generator class="identity" />
    </id>

    <property name="Name" column="Name" />
    <property name="NumberOfBuckets" column="NumberOfBuckets"  />
    <property name="SearchCriteriaOne" column="SearchCriteriaOne" />

    <bag name="_Businesses" cascade="all">
      <key column="SubCategoryId"/>
      <one-to-many 
         class="HQData.Objects.Business, HQData"/>
    </bag>

    <bag name="_Buckets" cascade="all">
      <key column="SubCategoryId"/>
      <one-to-many
         class="HQData.Objects.Bucket, HQData"/>
    </bag>

  </class>
</hibernate-mapping>

전에이 문제를 겪은 사람이 있습니까?

전체 오류 메시지는 다음과 같습니다.

MappingException : 지속 기 없음 : HQData.Objects.SubCategory] NHibernate.Impl.SessionFactoryImpl.GetEntityPersister (String entityName, Boolean throwIfNotFound)
 c : \ CSharp \ NH2.0.0 \ nhibernate \ src \ NHibernate \ Impl \ SessionFactoryImpl.cs : 766 NHibernate.Impl.SessionFactoryImpl.GetEntityPersister (String entityName)에서
 c : \ CSharp \ NH2.0.0 \ nhibernate \ src \ NHibernate \ Impl \ SessionFactoryImpl.cs : 752 NHibernate.Event.Default.DefaultLoadEventListener.OnLoad (LoadEvent 이벤트, LoadType loadType)
 c : \ CSharp \ NH2.0.0 \ nhibernate \ src \ NHibernate \ Event \ Default \ DefaultLoadEventListener.cs : 37 NHibernate.Impl.SessionImpl.FireLoad (LoadEvent 이벤트, LoadType loadType)
 c : \ CSharp \ NH2.0.0 \ nhibernate \ src \ NHibernate \ Impl \ SessionImpl.cs : 2054 NHibernate.Impl.SessionImpl.Get (문자열 entityName, 오브젝트 ID)
 c : \ CSharp \ NH2.0.0 \ nhibernate \ src \ NHibernate \ Impl \ SessionImpl.cs : 1029 NHibernate.Impl.SessionImpl.Get에서 (Type entityClass, Object id)
 c : \ CSharp \ NH2.0.0 \ nhibernate \ src \ NHibernate \ Impl \ SessionImpl.cs : 1020 NHibernate.Impl.SessionImpl.Get (개체 ID)
 c : \ CSharp \ NH2.0.0 \ nhibernate \ src \ NHibernate \ Impl \ SessionImpl.cs : 985 HQData.DataAccessUtils.NHibernateObjectHelper.LoadDataObject (Int32 Id)
 C : \ Development \ HQChannelRepo \ HQ Channel Application \ HQChannel \ HQData \ DataAccessUtils \ NHibernateObjectHelper.cs : 42에서 HQ Website.LocalSearch.get_subCategory ()
 C : \ Development \ HQChannelRepo \ HQ Channel Application \ HQChannel \ HQWebsite \ LocalSearch.aspx.cs : 17 HQWebsite.LocalSearch.Page_Load (Object sender, EventArgs e)에서
 C : \ Development \ HQChannelRepo \ HQ Channel Application \ HQChannel \ HQWebsite \ LocalSearch.aspx.cs : 27 System.Web.Util.CalliHelper.EventArgFunctionCaller (IntPtr fp, Object o, Object t, EventArgs e) +15 System.Web에서 .Util.CalliEventHandlerDelegateProxy.Callback (Object sender, EventArgs e) +33 System.Web.UI.Control.OnLoad (EventArgs e) +99 System.Web.UI.Control.LoadRecursive () +47 System.Web.UI.Page .ProcessRequestMain (부울 includeStagesBeforeAsyncPoint, 부울 includeStagesAfterAsyncPoint) +1436

Update , 여기 시나리오에 대한 해결책 은 다음과 같습니다. 코드를 변경했으며 런타임 중에 구성 파일에 어셈블리를 추가하지 않았습니다.


세션 팩토리 구성에 맵핑 어셈블리를 추가하지 않은 것 같습니다.

app.config를 사용하는 경우 ...

.
.
    <property name="show_sql">true</property>
    <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
    <mapping assembly="Project.DomainModel"/>  <!-- Here -->
</session-factory>
.
.

NHibernate를 처음 접하는 사람에게는 분명하지만 매우 유용한 정보입니다.

모든 XML 맵핑 파일은 기본 컨텐츠가 아닌 임베드 된 자원 으로 처리되어야합니다 . 이 옵션은 파일 속성에서 빌드 조치 속성을 편집하여 설정됩니다.

그런 다음 XML 파일이 어셈블리에 임베드되고 NHibernate의 구성 단계 동안 프로젝트 시작시 구문 분석됩니다.


내 문제는 매핑 XML의 이름에 .hbm을 넣는 것을 잊었다는 것입니다. 또한 포함 된 리소스로 만들어야합니다!


나는 이것을 여기서 꺼냈다 .

필자의 경우 매핑 클래스는 공개되지 않았습니다. 다시 말해,

public class UserMap : ClassMap<user>  // note the public!

나는 방금했다 :

class UserMap : ClassMap<user>

Spending about 4 hours on googling and stackoverflowing, trying all of stuff around there, i've found my error:

My mapping file was called .nbm.xml instead of .hbm.xml. That was insane.


I had similar problem, and I solved it as folows:

I working on MS SQL 2008, but in the NH configuration I had bad dialect: NHibernate.Dialect.MsSql2005Dialect if I correct it to: NHibernate.Dialect.MsSql2008Dialect then everything's working fine without a exception "No persister for: ..." David.


I was also adding the wrong assembly during initialization. The class I'm persisting is in assembly #1, and my .hbm.xml file is embedded in assembly #2. I changed cfg.AddAssembly(... to add assembly #2 (instead of assembly #1) and everything worked. Thanks!


To add to Amol's answer, don't make the mistake of specifying the Interface class type. Make sure you specify the implementation class. (Ie. don't use IDomainObjectType). Not that I made this mistake... :)


Should it be name="Id"? Typos are a likely cause.

Next would be to try it out with a non-generic test to make sure you're passing in the proper type parameter.

Can you post the entire error message?


I had the same problem because I was adding the wrong assembly in Configuration.AddAssembly() method.


This error occurs because of invalid mapping configuration. You should check where you set .Mappings for your session factory. Basically search for ".Mappings(" in your project and make sure you specified correct entity class in below line.

.Mappings(m => m.FluentMappings.AddFromAssemblyOf<YourEntityClassName>())

If running tests on the repository from a seperate assembly, then make sure your Hibernate.cfg.xml is set to output always in the bin directory of said assembly. This wasn't happening for us and we got the above error in certain circumstances.

Disclaimer: This might be a slightly esoteric bit of advice, given that it's a direct result of how we structure our repository integration test assemblies (i.e. we have a symbolic link from each test assembly to a single Hibernate.xfg.xml)


Don't forget to specify mapping information in .config file

e.g.

where MyApp.Data is assembly that contains your mappings


Had a similar problem when find an object by id... All i did was to use the fully qualified name in the class name. That is Before it was :

find("Class",id)

Object so it became like this :

find("assemblyName.Class",id)

Make sure you have called the CreateCriteria(typeof(DomainObjectType)) method on Session for the domain object which you intent to fetch from DB.

참고URL : https://stackoverflow.com/questions/57804/nhibernate-mappingexception-no-persister-for-xyz

반응형