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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:29:09+00:00 2026-05-12T07:29:09+00:00

I’m attempting to map an object model for Promotions; i.e., a customer enters a

  • 0

I’m attempting to map an object model for “Promotions”; i.e., a customer enters a promo code during signup.

Different promo codes might have different types of “benefits”, meaning what we are giving to the customer.
For example: promo code XYZ123 will give the customer free minutes in his or her account, while a different promo code will offer various discounts off of the various subscription plans that the user can choose from when signing up.

In my domain model, I’ve modeled the different types of benefits as subclasses with an abstract superclass which has the common properties. I’ve chosen to model the different types as subclasses since some types of benefits will need different properties.

public abstract class Benefit {
    //getters/setters for common attributes
}

public class FreeMinutesBenefit extends Benefit {
    public int getFreeMinutes() {...}
    public void setFreeMinutes(int minutes} {...}
}

public class PriceDiscountBenefit extends Benefit {
    public Map<Plan, BigDecimal> getDiscountMap() {...}
    public void setDiscountMap(Map<Plan, BigDecimal> map) {...}
}

Rough SQL schema:

-- Parent table, maps promotion to benefits
create table Promo_Benefit (
    map_id integer auto-generated PRIMARY KEY,
    promo_id integer references PROMOTION(promo_id),
    type_id integer references BENEFIT_TYPES(type_id)
);

create table BenefitDetails_FreeMinutes (
    map_id integer PRIMARY KEY,
    minutes integer not null,
    FOREIGN KEY (map_id) references Promo_Benefit(map_id)
);

create table BenefitDetails_PriceDiscount (
    map_id integer references Promo_Benefit(map_id),
    plan_id integer references Plans(plan_id),
    reduced_price numeric not null,
    PRIMARY KEY (map_id, plan_id)
    FOREIGN KEY (map_id) references Promo_Benefit(map_id)
);

I’m able to successfully map the basic properties of each subclass in my Hibernate mapping files, but I’m having trouble figuring out how to map the association
between the PriceDiscountBenefit subclass and the Plan class.

I imagine this is because the primary key of the subclass table (BenefitDetails_PriceDiscount) isn’t simply the map_id column – in other words, multiple rows in this subclass table will form a single PriceDiscountBenefit entity. From what I can see, it seems as if table-per-subclass support in Hibernate is meant for instances where a single row in the subclass table maps to a single row in the parent table – and mapping a <map> should refer to a second table which contains the keys/values.

Am I mapping this completely wrong? I can’t tell if I’m having trouble because I’m butchering the table-per-subclass pattern.

  • 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-12T07:29:10+00:00Added an answer on May 12, 2026 at 7:29 am

    Table-per-subclass strategy means you will have a table for each class in your hierarchy (including abstract classes, if any) and they will all have shared primary key. In your case that means you would have a separate table for each of Benefit, FreeMinutesBenefit and PriceDiscountBenefit classes. Your table names are a bit confusing and table structure is somewhat inconsistent with table-per-subclass.

    Assuming that map_id is the shared primary key, BenefitDetails_PriceDiscount table must define it as such. plan_id belongs to a different (‘mapping) table that will hold a map betweenPriceDiscountBenefit,Plan` and the decimal value. In other words:

    create table BenefitDetails_PriceDiscount (
            map_id integer PRIMARY KEY,
            ... /* any other attributes, perhaps? */
            FOREIGN KEY (map_id) references Promo_Benefit(map_id)
    );
    
    create table BenefitDetails_PriceDiscount_Map (
            map_id integer references Promo_Benefit(map_id),
            plan_id integer references Plans(plan_id),
            reduced_price numeric not null,
            PRIMARY KEY (map_id, plan_id)
            FOREIGN KEY (map_id) references Promo_Benefit(map_id)
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.