Frequently asked questions and solutions for NHibernate

Source: Internet
Author: User

problem 1 :

Exception: In expected: <end-of-text> (possibly an invalid or unmapped class name is used in the query) [from Customer]

Solution: See if the HQL statement query is an entity class and the mapping file property is correct: Copy to output directory à always copy. The build operation à embedded Resource.

problem 2 :

Exception: The Required property ' name ' is missing.

Solution: See if the name attribute is missing from the <property> node in the mapping file

problem 3 :

Exception: The type initializer for "NHibernate.Proxy.CastleProxyFactory" throws an exception.

Solution: NHibernate version issue. Remove the reference to NHibernate from the data access layer and the interface layer, referencing the nhibernate2.0 component, changing the configuration file (App.config/web.config), to nhibernate-.ga-src/src/ Nhibernatetext Copy the configuration information from the App. Config. NHibernate below.

problem 4 ,

Exception:Could not find the dialect in the configuration

Solution: Configuration file error. The Web project should be configured in the CONFIG. nhibernate configuration file. The application configures NHibernate in App. config.

problem 5.

Exception: Could not resolve Property:customerid Of:CompanyModels.Customer [from Companymodels.customer C where c.customerid=:c Ustomerid]

Solution: The field in the HQL statement is a property that represents the entity class and is case-sensitive.

problem 6 ,

Exception: should not

Solution: Change 2.0 to 2.2, 2.0 when generating the mapping file in Codesmith, and Nhibernate2 for 2.2

problem 7 ,

Exception: "Bag" in the element namespace "urn:nhibernate-mapping". "Many-to-many" in the child element namespace "urn:nhibernate-mapping". Invalid. Should be a list of possible elements: "Loader, Sql-insert, sql-update, Sql-delete, Sql-delete-all, filter" in the namespace "urn:nhibernate-mapping".

Solution: Many-to-many relationship mapping errors, see if there are multiple <many-to-many> nodes in the mapping file, if you delete one. Just refer to the corresponding entity class. Such as:

<bag name= "orderproducts" table= "Orderproduct" inverse= "false" lazy= "true" cascade= "All-delete-orphan" >

<key>

<column name= "' Order '" length= "4" sql-type= "int" not-null= "true"/>

</key>

<many-to-many class= "Companymodels.order, Companymodels" >

<column name= "Order" length= "4" sql-type= "int" not-null= "true"/>

</many-to-many>

<many-to-many class= "companymodels.product, Companymodels" >

<column name= "Product" length= "4" sql-type= "int" not-null= "true"/>

</many-to-many>

</bag>

Remove the first <many-to-many> to resolve.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.