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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:47:05+00:00 2026-05-13T22:47:05+00:00

I have a file attachment class (FileAttachment) which is used in several other classes.

  • 0

I have a file attachment class (FileAttachment) which is used in several other classes.

e.g. An article contains multiple attachments. A category contains multiple attachments. These attachments are actually the same FileAttachment class but for obvious reason they are persisted in different tables. e.g. file attachment for an article in Article_FileAttachments table and category file attachments in a Category_FileAttachments table.

How can i represent this relationship in the nhibernate mappings? thx

  • 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-13T22:47:05+00:00Added an answer on May 13, 2026 at 10:47 pm

    Please see Chapter 8 for polymorphic mapping rules with NHibernate.

    In short, you will need a discriminator column to specify what discriminator persists to what table. Here’s an instance from the NHibernate documentation, OR if you use inheritance, you will only need to map your derived classes as subclasses and specify the datatable name for each of them from within your base type class mapping.

    <class name="IPayment" table="PAYMENT">
      <id name="Id" type="Int64" column="PAYMENT_ID">
        <generator class="native"/>
      </id>
      <property name="Amount" column="AMOUNT"/>
      ...
      <joined-subclass name="CreditCardPayment" table="CREDIT_PAYMENT">
        <key column="PAYMENT_ID"/>
        ...
      </joined-subclass>
      <joined-subclass name="CashPayment" table="CASH_PAYMENT">
        <key column="PAYMENT_ID"/>
        ...
      </joined-subclass>
      <joined-subclass name="ChequePayment" table="CHEQUE_PAYMENT">
        <key column="PAYMENT_ID"/>
        ...
      </joined-subclass>
    </class>
    

    You may observe that a Payment is a payment, whatever its type of payment. So, it is mapped as a IPayment. Then, subcategorized in multiple tables which represents each type of payment by its discriminator column.

    Chapter 8 – Polymorphic mapping

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

Sidebar

Related Questions

Suppose I have file which goes like this : a void measure() { a
Say I have file A, in middle of which have a tag string #INSERT_HERE#.
What I have is a Theme model, which contains many Assets. Assets are using
I have two models like this: class A(models.Model): attachment = FileField(upload_to='a') class B(models.Model): attachment
I have a small form in which the user uploads a file. What I
I have a POCO class called Attachment that maps to a table in SqlServer
I have a paperclip'd file that I want to add as an attachment to
I have video model with the following definition: class Video require 'carrierwave/orm/activerecord' mount_uploader :attachment,
I have a class that extends RemoteServiceServlet. This class has several methods, in one
I used to have this code for sending mails: class MailTimerMailer < ActionMailer::Base def

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.