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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:49:06+00:00 2026-05-13T16:49:06+00:00

Let’s say that I have a class/table called Images that, as it stands right

  • 0

Let’s say that I have a class/table called Images that, as it stands right now, is bound in a manner similar to this:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="Domain.Image, Domain" table="Images">
    <id name="id" column="ImageID" access="field" unsaved-value="0">
      <generator class="identity" />
    </id>    
<!-- other properties -->
    <property name="AssociatedObjectID" column="AssociatedObjectID" />
    <property name="AssociatedObjectType" column="AssociatedObjectType" />
  </class>
</hibernate-mapping>

Up until this point, this schema has worked, because a image was only associated with one object, so I could keep that reference without a discriminator.

However, now I wish to have a collection of these images on another entity called a PhotoShoot. Each PhotoShoot can have several images.

Is there a way to bind a collection such that I can have a List<Image> within PhotoShoot without extracting a base class and using the table-per-hierarchy inheritance pattern?

And if not, is table-per-hierarchy really the best way to go here? I hate to create subclasses, especially since there is nothing that needs to be abstracted from the Image entity.

  • 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-05-13T16:49:06+00:00Added an answer on May 13, 2026 at 4:49 pm

    I would map this as an IList<Images> property on PhotoShoot, mapped via a join table (many-to-many).

    If the ordering of the list is important, map as a list otherwise as a bag. I have included both mappings.

    <class name="Domain.PhotoShoot, Domain" table="PhotoShoot">
        <id name="id" column="PhotoShootId" access="field" unsaved-value="0">
          <generator class="identity" />
        </id>    
        <!-- other properties -->
    
        <!-- unordered list -->
        <bag name="Images" table="PhotoShoot_Image" fetch="join" cascade="all-delete-orphan">
            <key column="PhotoShootId"/>
            <many-to-many class="Domain.Image, Domain" column="ImageId" />
        </bag>
    
        <!-- ordered list -->
        <list name="Images" table="PhotoShoot_Image" fetch="join" cascade="all-delete-orphan">
            <key column="PhotoShootId"/>
            <imdex column="position" />
            <many-to-many class="Domain.Image, Domain" column="ImageId" />
        </list>
    </class>
    
    public class PhotoShoot
    {
        IList<Image> Images { get; set; }
    }
    

    Using @ddango’s original class mapping we could instead do the following.

    <class name="Domain.PhotoShoot, Domain" table="PhotoShoot">
        <bag name="Images" table="Image" fetch="join" where="AssociatedObjectType='PhotoShoot'">
            <key column="AssociatedObjectId"/>
            <one-to-many class="Domain.Image, Domain" />
        </bag>
    </class>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have an abstract parent class called shape, and that there are
Let me explain best with an example. Say you have node class that can
Let's say for a moment that I have the following module in python: class
Let's say you have a class library project that has any number of supplemental
Let's say that I have classes like this: public class Parent { public int
Let's say you have a class, with certain properties, and that you tried your
Let's say I have a posts table that has many comments (and a comment
Let's say I have a table with a Color column. Color can have various
Let's say that I have a SQLite database that I create in a separate
Let's say I have two text files that I need to extract data out

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.