2011-01-08 16 views
6

समस्या उत्पन्न हुईNHibernate: इस "बोली" कॉन्फ़िगरेशन समस्या को हल करने के लिए कैसे करें

रनटाइम पर, मुझे हमेशा निम्न NHibernate.MappingException मिलता है:

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

हां, इसकी बिल्ड क्रिया Embedded Resource पर सेट है। इनरएक्सप्शन का कहना है:

"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. विजुअल स्टूडियो 2010, .NET 4.0 को लक्षित करना;
  3. NHibernate 3.0.0.GA;
  4. SQL सर्वर 2005.

प्रश्न

मैंने पहले से ही बोलीप्रणाली को कॉन्फ़िगरेशन की रेखा पर डालने का प्रयास किया है, और यह न तो काम करता है।

मेरे पास इस बोली समस्या को हल करने के लिए कैसे करें?

+1

एनएचबेर्नेट स्रोत कोड डाउनलोड करें, ऐप से संलग्न करें और फेंकने पर अपवाद को पकड़ने का प्रयास करें। –

+0

ने अभी तक एनएच 3 के साथ काम नहीं किया है - मैं आपकी कॉन्फ़िगरेशन फ़ाइल में nurnernate-config -___ 2.2 ____ पढ़ने के लिए थोड़ा आश्चर्यचकित हूं। – Marijn

+0

इसके बारे में कोई समाधान? – Kiquenet

उत्तर

9

मेरे लिए allright लग रहा है ... आप इन से संबंधित प्रश्नों को देखा है:

ये ऐसा आसान अपवाद है जो दिए गए अपवाद को बढ़ा सकता है।

+0

+1 मैंने उपर्युक्त जानकारी के बारे में सुनिश्चित किया है, लेकिन फिर भी त्रुटि बनी हुई है। मैं देखूंगा कि जनी ने अपनी टिप्पणी में क्या प्रस्तावित किया था इसके साथ मैं क्या कर सकता हूं। आपकी तरह की सहायता के लिए धन्यवाद! =) –

+0

हाय Marijn! मुझे खेद है, मुझे इस परियोजना को थोड़ी देर के लिए अलग रखना पड़ा और मैं अभी तक इसके लिए तत्पर नहीं हूं। मैं या तो स्वीकार करता हूं या आपको बताता हूं कि बाद में काम नहीं कर रहा है जब मैं इस परियोजना पर वापस आ सकता हूं जिससे यह प्रश्न जारी किया गया है। आपकी समझ और धैर्य के लिए धन्यवाद। =) –

3

दो बातें इस मुद्दे को ठीक होगा:

इसका उपयोग न करें:

Configuration c = new Configuration(); 

इसके बजाय, इस का उपयोग करें:

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

सुनिश्चित करें कि या तो आप अपने हाइबरनेट में ऐसा करते हैं। cfg.xml फ़ाइल:

<mapping assembly="Your assembly"/> 

या

AddAssembly(Assembly.GetCallingAssembly()); 

दोनों करना समस्या पैदा करेगा।

संबंधित मुद्दे