2011-01-08 10 views
6

문제가 발생했습니다.NHibernate :이 "dialect"설정 문제를 해결하는 방법

런타임에 나는 항상 다음과 같은 NHibernate.MappingException를 얻습니다 :

"Could not compile the mapping document: GI.InventoryManager.CYB.Mappings.Part.hbm.xml" 

예, 빌드 작업은 Embedded Resource으로 설정됩니다. InnerException 메시지 :

"Could not find the dialect in the configuration" 

다음은 hibernate.cfg.xml라는 구성 파일입니다.

<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" > 
    <session-factory> 
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> 
    <property name="connection.connection_string"> 
     Server=(local);initial catalog=GI_IM_CYB;Integrated Security=SSPI 
    </property> 
    <property name="adonet.batch_size">10</property> 
    <property name="show_sql">false</property> 
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> 
    <property name="use_outer_join">true</property> 
    <property name="command_timeout">60</property> 
    <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property> 
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory,  NHibernate.ByteCode.Castle</property> 
    </session-factory> 
</hibernate-configuration> 

실제로 Configuration_Templates 폴더의 복사 붙여 넣기입니다. 다음 정보 만 변경 :

private void configBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { 
    Configuration c = new Configuration(); 
    c.AddAssembly(typeof(Part).Assembly); 
    lock (_sessionFactory) { 
     _sessionFactory = c.BuildSessionFactory(); 
    } 
} 

옵션 정보

<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true" assembly="GI.InventoryManager.CYB" namespace="GI.InventoryManager.CYB.Types"> 
    <class name="Part" table="Parts" lazy="true"> 
    <id name="Id" column="part_id"> 
     <generator class="native"/> 
    </id> 
    <properties name="Description"/> 
    <properties name="Number"/> 
    <properties name="InStockQty"/> 
    <properties name="Cost"/> 
    </class> 
</hibernate-mapping> 


public class Part { 
    #region Private Members 

    private string _description; 
    private string _number; 

    #endregion 
    #region Constructors 

    /// <summary> 
    /// Initializes an instance of the GI.InventoryManager.CYB.Types.Part class. 
    /// </summary> 
    public Part() { } 

    #endregion 
    #region Properties 

    /// <summary> 
    /// Gets or sets the description of this part. 
    /// </summary> 
    public virtual string Description { 
     get { 
      return _description; 
     } set { 
      if (!string.IsNullOrWhiteSpace(value)) 
       _description = value.Trim(); 
     } 
    } 

    /// <summary> 
    /// Gets the underlying datastore unique identifier. 
    /// </summary> 
    public virtual int Id { get; private set; } 

    /// <summary> 
    /// Gets or sets the user-defined number. 
    /// </summary> 
    public virtual string Number { 
     get { 
      return _number; 
     } set { 
      if (!string.IsNullOrWhiteSpace(value)) 
       _number = value.Trim(); 
     } 
    } 

    /// <summary> 
    /// Gets or sets the in-stock quantity. 
    /// </summary> 
    public virtual int InStockQty { get; set; } 

    /// <summary> 
    /// Gets or sets the cost. 
    /// </summary> 
    public virtual double? Cost { get; set; } 

    /// <summary> 
    /// Gets the inventory value for this part. 
    /// </summary> 
    /// <remarks> 
    /// <para> 
    /// This read-only property returns the product of <see cref="T:InStockQty"/> and <see cref="Cost"/>. 
    /// In case the <b>Cost</b> property does not have a value, zero is returned. 
    /// </para> 
    /// </remarks> 
    public double InventoryValue { 
     get { 
      if (Cost.HasValue) 
       return InStockQty * Cost.Value; 
      return 0.0; 
     } 
    } 

    #endregion 
    #region Methods 



    #endregion 
} 

환경

    :

    Session Factory: "Removed the NHibernate.Test namespace and let the property for itself" 
    Dialect: "From MsSql2000Dialect To MsSql2005Dialect" 
    Connection_String: "I changed the Initial Catalog attribute to input my own database name" 
    Factory Class: "From LinFu to Castle" 
    

    그리고 여기가 내 코드에서 사용하고 방법

  1. 윈도우 7 프로;
  2. Visual Studio 2010, 대상 .NET 4.0;
  3. NHibernate 3.0.0.GA;
  4. SQL Server 2005.

질문

이미 구성 줄에 dialect 속성을 넣으려고했으나 둘 다 작동하지 않았습니다.

내가 가진이 방언 문제를 해결하는 방법?

+1

NHibernate 소스 코드를 다운로드하고, 앱에 첨부하고, 던져 질 때 예외를 잡으려고 노력하십시오. –

+0

은 아직 NH 3에서 작동하지 않았습니다. 설정 파일에서 urn : nhibernate-configuration -___ 2.2 ____을 읽으면 약간 놀랍습니다. – Marijn

+0

그것에 관한 어떤 해결책이 있나요? – Kiquenet

답변

9

는 이러한 관련 질문을 보았다 ... 나에게 무사 보이는 :

이들 주어진 예외를 발생시킬 수있는 실수를 저지르는 것이 쉽습니다.이 문제가 해결됩니다

+0

+1 나는 위에서 언급 한 정보를 확인했지만 여전히 오류는 계속 발생합니다. Jani가 자신의 의견에서 제안한 내용으로 내가 할 수있는 것을 알게 될 것입니다. 친절한 도움에 감사드립니다! =) –

+0

안녕하세요, Marijn! 죄송합니다. 잠시 동안이 프로젝트를 제쳐두어서야 했으므로 지금은 기대할 수 없습니다. 나는이 질문이 발행 된이 프로젝트로 돌아올 수있을 때 나중에 일하지 않는 것을 받아들이거나 말할 것입니다. 이해와 인내심에 감사드립니다. =) –

3

두 가지 :

이 사용하지 마십시오 :

대신
Configuration c = new Configuration(); 

, 이것을 사용 :

Configuration c = new Configuration().Configure(); 

하는 중 당신이 최대 절전 모드에서이 작업을 수행해야합니다. cfg.xml 파일 :

<mapping assembly="Your assembly"/> 

OR

AddAssembly(Assembly.GetCallingAssembly()); 

둘 다 수행하면 문제가 발생합니다.

관련 문제