Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7883567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:34:00+00:00 2026-06-03T04:34:00+00:00

I am learning NHibernate, but failed. I sense that the error messages are not

  • 0

I am learning NHibernate, but failed. I sense that the error messages are not accurate.

Please help .

error message is

The following types may not be used as proxies:
SecondSolution.Domain.Product: method get_Id should be 'public/protected virtual' or 'protected internal virtual'
SecondSolution.Domain.Product: method set_Id should be 'public/protected virtual' or 'protected internal virtual'
SecondSolution.Domain.Product: method get_Name should be 'public/protected virtual' or 'protected internal virtual'
SecondSolution.Domain.Product: method set_Name should be 'public/protected virtual' or 'protected internal virtual'
SecondSolution.Domain.Product: method get_Category should be 'public/protected virtual' or 'protected internal virtual'
SecondSolution.Domain.Product: method set_Category should be 'public/protected virtual' or 'protected internal virtual'
SecondSolution.Domain.Product: method get_Discontinued should be 'public/protected virtual' or 'protected internal virtual'
SecondSolution.Domain.Product: method set_Discontinued should be 'public/protected virtual' or 'protected internal virtual'
   at NHibernate.Cfg.Configuration.ValidateEntities() in c:\Users\oskar.berggren\Documents\Projects\nhibernate-core-3\src\NHibernate\Cfg\Configuration.cs:line
1052
   at NHibernate.Cfg.Configuration.Validate() in c:\Users\oskar.berggren\Documents\Projects\nhibernate-core-3\src\NHibernate\Cfg\Configuration.cs:line 959
   at NHibernate.Cfg.Configuration.BuildSessionFactory() in c:\Users\oskar.berggren\Documents\Projects\nhibernate-core-3\src\NHibernate\Cfg\Configuration.cs:li
ne 1251
   at SecondSolution.Program.Main(String[] args) in C:\vs_workspace\SecondSolution\SecondSolution\Program.cs:line 22
Press any key to continue . . .

Class file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SecondSolution.Domain
{
    class Product
    {
        public Product()
        {
            this.Name = "John";
        }
        public Guid Id { get; set; }        
        public string Name { get; set; }        
        public string Category { get; set; }        
        public bool Discontinued { get; set; }
    }
}

mapping

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"                    
                   assembly="SecondSolution"                    
                   namespace="SecondSolution.Domain">
  <class name="Product">
    <id name="Id">
      <generator class="guid" />
    </id>
    <property name="Name" />
    <property name="Category" />
    <property name="Discontinued" />
  </class>
</hibernate-mapping>

config:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.MsSqlCeDialect</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlServerCeDriver</property>
    <property name="connection.connection_string">Data Source=FirstSample.sdf</property>
    <property name="show_sql">true</property>  
  </session-factory>
</hibernate-configuration>

main class

static void Main(string[] args)
        {
            try
            {
                Configuration cfg = new Configuration();
                cfg.Configure("Mappings/hibernate.cfg.xml");
                //cfg.Configure();

                cfg.AddAssembly(typeof(Product).Assembly);

                NHibernate.ISessionFactory m_SessionFactory = cfg.BuildSessionFactory();
                NHibernate.ISession session = m_SessionFactory.OpenSession();
                Product product = new Product();
                session.SaveOrUpdate(product);
            } catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }

        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T04:34:01+00:00Added an answer on June 3, 2026 at 4:34 am

    As the others say – you must make your properties virtual.
    But this is only needed if you want your entity to be able to lazy load, read up on it here http://nhforge.org/wikis/howtonh/lazy-loading-eager-loading.aspx

    If you dont want lazy loading you can disable it

    <class name="Product" Lazy="false">
    

    Then you wont need virtual properties.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning Hibernate Validator. I see that I can add an error message text
I'm new to NHibernate and not very good at C#, but I'm learning. I
I'm learning NHibernate to learn a more robust ORM than linq to sql, but
I'm learning NHibernate and hoping you guys could help me a bit about Tag
I've got a personal (learning) project that uses Castle Windsor (with the NHibernate facility)
I'm just learning nHibernate and have come across what probably is a simple issue
I have just started learning NHibernate. Over the past few months I have been
The setup: Winform/ASP.NET MVC projects. Learning NHibernate SQL-Server driven apps I work with clients
I'm learning Fluent NHibernate (and by extension, NHibernate generally). I'm using auto-mapping with some
I am just learning NHibernate. I have been using examples from the documentation and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.