2011-01-08 17 views
6

problemem spotykanymNHibernate: Jak rozwiązać ten "dialekt" problem z konfiguracją

W czasie wykonywania, zawsze pojawia się następujący NHibernate.MappingException:

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

Tak, jego działania kompilacji jest ustawiony na Embedded Resource. InnerException mówi:

"Could not find the dialect in the configuration" 

wymaganych informacji

Oto mój plik konfiguracyjny o nazwie 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> 

co faktycznie jest kopią pasty z Configuration_Templates folder, w którym ja zmieniono tylko następujące informacje:

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" 

A oto jak używam go w moim kodu:

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

Opcjonalny Informacja

<?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 
} 

Środowisko

  1. Windows 7 Pro;
  2. Visual Studio 2010, targetowanie .NET 4.0;
  3. NHibernate 3.0.0.GA;
  4. SQL Server 2005.

Pytanie

Próbowałem już umieścić właściwość dialekt na linii konfiguracji, i to nie działało.

Jak rozwiązać ten problem z dialektem, który mam?

+1

Pobierz kod źródłowy NHibernate, dołącz do aplikacji i spróbuj złapać wyjątek podczas rzucania. –

+0

nie pracowałem jeszcze z NH 3 - jestem nieco zaskoczony, czytając urna: nhibernate-configuration -___ 2.2 ____ w twoim pliku konfiguracyjnym. – Marijn

+0

jakieś rozwiązanie na ten temat? – Kiquenet

Odpowiedz

9

Wygląda w porządku dla mnie ... widziałeś te związane pytania:

Te są łatwe błędy, które mogą podnieść dany wyjątek.

+0

+1 Upewniłem się o wyżej wymienionych informacjach, ale mimo to błąd nadal występuje. Zobaczę, co mogę zrobić z tym, co zaproponował Jani w swoim komentarzu. Dzięki za życzliwą pomoc! =) –

+0

Cześć Marijn! Przykro mi, musiałem odłożyć ten projekt na jakiś czas i nie mogę na razie tego oczekiwać. Przyjmuję lub powiem ci, co nie działa później, kiedy mogę wrócić do tego projektu, z którego to pytanie jest wydawane. Dzięki za wyrozumiałość i cierpliwość. =) –

3

dwie rzeczy będzie rozwiązać problem:

nie wolno używać:

Configuration c = new Configuration(); 

Zamiast tego użyj:

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

Upewnij się, że albo można to zrobić w hibernacji. Plik cfg.xml:

<mapping assembly="Your assembly"/> 

LUB

AddAssembly(Assembly.GetCallingAssembly()); 

Wykonanie obu spowoduje wystawienie.

Powiązane problemy