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 8448029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:19:13+00:00 2026-06-10T10:19:13+00:00

I have the following classes which I would like to map using NHibernate class

  • 0

I have the following classes which I would like to map using NHibernate

class User
{
    long Id {get; set;}
    IList<UserPassword> OldPasswords {get; set}
}

class UserPassword
{
    long UserId {get; set;}
    string Password {get; set;}
    DateTime CreateDtm {get; set;}
}

In the UserPassword table in the database (Oracle) UserId, Password and CreateDtm are a composite key (I cant change this)

At present my mapping files look like

<hibernate-mapping assembly="DomainEntities" namespace="DomainEntities.Models" xmlns="urn:nhibernate-mapping-2.2">

  <class name="User" table="USERS" lazy="true" >
    <id name="Id">
      <column name="USER_ID" sql-type="NUMBER" not-null="true" unique="true"/>
      <generator class="identity"/>
    </id>

    <bag name="OldPasswords" cascade="all" inverse="true">
      <key column="USER_ID" not-null="true" />
      <one-to-many class="UserPassword" />
    </bag>

  </class>
</hibernate-mapping>

<hibernate-mapping assembly="DomainEntities" namespace="DomainEntities.Models" xmlns="urn:nhibernate-mapping-2.2">

  <class name="UserPassword" table="USER_PASSWORDS" lazy="true" >

    <composite-id>
      <key-property name="UserId" column="USER_ID" />
      <key-property name="Password" column="OLD_PASSWORD" />
      <key-property name="CreateDtm" column="CREATE_DATE" />
    </composite-id>

  </class>

</hibernate-mapping>

When querying for the user object, its loading the user passwords correctly, however, I cant add or remove a new password to the list.

I have tried adding in a mapping on the User object, but when trying to commit the transaction, its thrown an exception on an invalid array index for the CreateDtm. I suspect this is because of the composite key.

Am I missing something in my mapping, or is this a scenario that just cant be done?

  • 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-10T10:19:14+00:00Added an answer on June 10, 2026 at 10:19 am

    I was missing the tag in the composite id.

    The composite-id now looks like

    <composite-id> 
      <key-many-to-one name="User" column="USER_ID" lazy="proxy" class="User" /> 
      <key-property name="Password" column="OLD_PASSWORD" /> 
      <key-property name="CreateDtm" column="CREATE_DATE" /> 
    </composite-id> 
    

    The other part to this problem, was the cascade mode, on the parent. I needed to set cascade to “add-delete-orphan” to delete the items removed from the collection.

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

Sidebar

Related Questions

I have the following two classes: public class User { public Integer userId; //
I have something like the following classes: public class Animal { ... } public
I have the following that I would like wrapped as units. <div class='tag-box'> <a
I have set of classes which inherit from a single super class: Super |
I have type classes, for all of which I would like to have some
In my current project, I have classes which are modeled like the following. At
I have the following Classes and am using EF 4.2 Code First public class
I have the following classes: public class Note { public string Text { get;
I have the following script which works: classes = $(this).attr(class).split('_'); If $(this) 's class
I have a project which it's domain contain following classes: Courier Customer Food Order

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.