2011-02-25 1 views
2

session.GetNamedQuery()를 호출 할 때 일관되게 "명명 된 쿼리를 알 수 없음"MappingException이 발생합니다. NHibernate 3.0에서 Fluent를 사용하고 있으며 hbm.xml 파일에 쿼리가 있습니다. 일을 단순하게하기 위해, 나는 같은 어셈블리에 모든 것을 가지고 있습니다. xml 파일의 Build Action을 "Embedded Resource"로 설정했습니다.session.GetNamedQuery()에 "Named Query Not Know"오류가 발생합니다.

내 구성은 다음과 같습니다

var nhConfig = Fluently.Configure() 
        .Database(SQLAnywhereConfiguration 
        .SQLAnywhere10 
        .ConnectionString("uid='dba'; pwd='sql'; dsn=db")) 
        .ExposeConfiguration(c => c.SetProperty("current_session_context_class", "thread_static")) 
        .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Party>()) 
        .BuildConfiguration(); 

      var sessionFactory = nhConfig.BuildSessionFactory(); 


      ISession session = sessionFactory.OpenSession(); 
      CurrentSessionContext.Bind(session); 


      NHibernate.IQuery q = session.GetNamedQuery("GetFirstParty"); 

내 GetFirstParty.hbm.xml 파일은 다음과 같다 :

<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> 

    <query name="GetFirstParty"> 
    <![CDATA[from Party p where p.CaseNumber = :CaseNumber]]> 
    </query> 

</hibernate-mapping> 

내가 무슨 말이냐 ???

도와주세요.

감사합니다,

마이크

답변

8

당신은 당신의 유창한 구성에서 HBM 매핑을 포함해야합니다

var nhConfig = Fluently.Configure() 
        .Database(SQLAnywhereConfiguration 
        .SQLAnywhere10 
        .ConnectionString("uid='dba'; pwd='sql'; dsn=db")) 
        .ExposeConfiguration(c => c.SetProperty(Environment.CurrentSessionContextClass, "thread_static")) 
        .Mappings(m => 
        { 
        m.FluentMappings.AddFromAssemblyOf<Party>(); 
        m.HbmMappings.AddFromAssemblyOf<Party>(); 
        }) 
        .BuildConfiguration(); 
+0

것은 정확히이었다. 팔! 고마워. –

+3

대답으로 선택하지 않는 이유는 무엇입니까? –