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

  • Home
  • SEARCH
  • 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 8845487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:45:10+00:00 2026-06-14T11:45:10+00:00

I am implementing a relatively simple model of user management using Castle Active Record

  • 0

I am implementing a relatively simple model of user management using Castle Active Record with NHibernate on top of MySql, and I have ran into an issue.

Let us say, I have two tables _users and _passwords described by the following SQL create statements

CREATE TABLE _users (
  id bigint(20) NOT NULL AUTO_INCREMENT,
  username char(32) NOT NULL,
  PRIMARY KEY (id),
  UNIQUE KEY username_UQ (username),
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE _passwords (
  id bigint(20) NOT NULL AUTO_INCREMENT,
  creation_date datetime NOT NULL,
  user_id bigint(20) NOT NULL,
  password_hash char(64) NOT NULL,
  valid_end_date datetime NOT NULL,
  PRIMARY KEY (id),
  UNIQUE KEY user_id_password_UQ (user_id,password_hash),
  KEY user_passwords_FK (user_id),
  CONSTRAINT user_passwords_FK FOREIGN KEY (user_id) REFERENCES _users (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

The idea is to keep a primitive password history, therefore, the passwords are kept in a separate table _passwords, which has many-to-one relation with the _users table.

Now, the following C# code models this structure using Castle Active Records

namespace DataEntities
{
    [ActiveRecord("_users")]
    public class User : ActiveRecordBase<User>
    {
        [PrimaryKey(PrimaryKeyType.Identity, "id", Access = PropertyAccess.NosetterLowercase)]
        public ulong Id
        {
            get;
            set;
        } // Id

        [Property("username", ColumnType = "String", NotNull = true, Unique = true)]
        [ValidateIsUnique]
        public string Username
        {
            get;
            set;
        } // Username

        [HasMany(typeof(Password))]
        public IList<Password> Passwords
        {
            get;
            set;
        } // Passwords

        public string ValidPasswordHash
        {
            get
            {
                DateTime l_dtNow = DateTime.Now;
                if (Passwords.Count != 1 || Passwords[0].ValidFrom >= l_dtNow || Passwords[0].ValidUntil <= l_dtNow)
                {
                    throw new Exception();
                }

                return Encoding.UTF8.GetString(Passwords[0].PasswordHash);
            }
        } // ValidPasswordHash

        public static User FindByCredentials(string i_sUsername, string i_sHashedPassword)
        {
            return FindOne(Restrictions.Eq("Username", i_sUsername), Restrictions.Eq("ValidPasswordHash", i_sHashedPassword));
        } // FindByCredentials
    } // User

    [ActiveRecord("_passwords")]
    public class Password : ActiveRecordBase<Password>
    {
        [PrimaryKey(PrimaryKeyType.Identity, "id", Access = PropertyAccess.NosetterLowercase)]
        public ulong Id
        {
            get;
            set;
        } // Id

        [BelongsTo("user_id", NotNull = true, UniqueKey = "_passwords_UQ1")]
        public ulong UserId
        {
            get;
            set;
        } // UserId

        [Property("password_hash", ColumnType = "UInt64", NotNull = true, UniqueKey = "_passwords_UQ1")]
        public byte[] PasswordHash
        {
            get;
            set;
        } // PasswordHash

        [Property("creation_date", ColumnType = "DateTime", NotNull = true)]
        public DateTime ValidFrom
        {
            get;
            set;
        } // ValidFrom

        [Property("valid_end_date", ColumnType = "DateTime", NotNull = true)]
        public DateTime ValidUntil
        {
            get;
            set;
        } // ValidUntil
    } // Password
} // DataEntities

and on my application start the framework is initialized

try
{
    ActiveRecordStarter.Initialize(ActiveRecordSectionHandler.Instance, typeof(Password),
                                                                        typeof(User));
}
catch (Exception l_excpt)
{
    // handle exception
}

At the end, when this code runs, it generates the following exception:

Castle.ActiveRecord.Framework.ActiveRecordException: ActiveRecord tried to infer details about the relation User.Passwords but it could not find a 'BelongsTo' mapped property in the target type DataEntities.Password
   at Castle.ActiveRecord.Framework.Internal.SemanticVerifierVisitor.VisitHasMany(HasManyModel model) in c:\daten\dev\External\Castle\AR2.0\ActiveRecord\Castle.ActiveRecord\Framework\Internal\Visitors\SemanticVerifierVisitor.cs:line 544
   at Castle.ActiveRecord.Framework.Internal.AbstractDepthFirstVisitor.VisitNodes(IEnumerable nodes) in c:\daten\dev\External\Castle\AR2.0\ActiveRecord\Castle.ActiveRecord\Framework\Internal\Visitors\AbstractDepthFirstVisitor.cs:line 45
   at Castle.ActiveRecord.Framework.Internal.AbstractDepthFirstVisitor.VisitModel(ActiveRecordModel model) in c:\daten\dev\External\Castle\AR2.0\ActiveRecord\Castle.ActiveRecord\Framework\Internal\Visitors\AbstractDepthFirstVisitor.cs:line 59
   at Castle.ActiveRecord.Framework.Internal.SemanticVerifierVisitor.VisitModel(ActiveRecordModel model) in c:\daten\dev\External\Castle\AR2.0\ActiveRecord\Castle.ActiveRecord\Framework\Internal\Visitors\SemanticVerifierVisitor.cs:line 122
   at Castle.ActiveRecord.Framework.Internal.AbstractDepthFirstVisitor.VisitNodes(IEnumerable nodes) in c:\daten\dev\External\Castle\AR2.0\ActiveRecord\Castle.ActiveRecord\Framework\Internal\Visitors\AbstractDepthFirstVisitor.cs:line 45
   at Castle.ActiveRecord.ActiveRecordStarter.RegisterTypes(ISessionFactoryHolder holder, IConfigurationSource source, IEnumerable`1 types, Boolean ignoreProblematicTypes) in c:\daten\dev\External\Castle\AR2.0\ActiveRecord\Castle.ActiveRecord\Framework\ActiveRecordStarter.cs:line 927
   at Castle.ActiveRecord.ActiveRecordStarter.Initialize(IConfigurationSource source, Type[] types) in c:\daten\dev\External\Castle\AR2.0\ActiveRecord\Castle.ActiveRecord\Framework\ActiveRecordStarter.cs:line 202
   at Global.Application_Start(Object sender, EventArgs e) in C:\Projects Code\xyz\Global.asax.cs:line 22

Well, I have stared endlessly at the UserId property of the Password class, I have googled, and now I am quite lost. So the community is my last hope… Can anybody help me understanding what causes this exception and how to fix it?

Thank you all in advance for your replies and comments.

  • 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-14T11:45:11+00:00Added an answer on June 14, 2026 at 11:45 am

    You should have a User User { get; set; } reference property instead of a foreign key.

    The official docs are a good place to start.

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

Sidebar

Related Questions

Implementing a simple Login screen using JSF and Spring and Hibernate. I have written
I'm implementing a relatively simple autosave system and I'd like to do so using
I have a relatively simple domain model, as shown by the diagram. I would
I am implementing a relatively complex object model service using WWSAPI (WCF hosted) and
I am implementing a simple recommendation system for a collection of user created components.
I'm learning Lisp. I'm implementing solution to some relatively simple problem. I'm thinking of
I am implementing a simple adder. However, I have a need for a bit
I am relatively new to implementing JQuery throughout an entire system, and I am
I'm implementing a new iPhone app and am relatively new to Cocoa development overall.
implementing publishActivity in PHP using the REST API using this code: $activity = array(

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.