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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:16:24+00:00 2026-05-20T13:16:24+00:00

My title is a bit vauge, here’s the problem I’m talking about. Say I

  • 0

My title is a bit vauge, here’s the problem I’m talking about.

Say I have:

class Bill
{
   public String legislationID;
   public BillStatus currentStatus;
}

//and

class BillStatus
{
   public String description; 
}

When persisted, BillStatus corresponds to a table with one row per possible state of a piece of legislation. (e.g. “On House Floor”, “On Senate Floor”, etc).

The problem I always run into is this:

As soon as behavior starts to vary based on which instance of BillStatus is attached to Bill, the whole thing becomes hard to represent. I see two options:

1) A lot of switches in Bill that branch behavior depending on current BillStatus
2) methods in bill status that accept Bill as a parameter, and have switches that execute different logic depending on identity of instance. (so kind of mimicking classes implementing a common interface)

Both these methods seem sloppy. What I would like to be able to do is this:

class abstract BillStatus
{
    public abstract String getDescription();
    public abstract void callForVote(Bill bill);
}

Then:

@SpecialEntityTag(whenRowValue="HOUSEFLOOR")
class BillStatusHouseFloor extends BillStatus
{
     /* special overrides for some methods */     
}

class BillStatusGeneric extends BillStatus
{
    /* standard implementation of BillStatus */
}

This has to be a common problem. Am I thinking about it the wrong way? Basically the goal is to encapsulate behavior that changes with particular value of a non-primitive child property.

  • 1 1 Answer
  • 2 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-20T13:16:25+00:00Added an answer on May 20, 2026 at 1:16 pm

    What prevents you from using your design?

    Hibernate (or JPA in general) is able to handle inheritance, and you may store a whole inheritance hierarchy in a single table with a discriminator column telling which subclass to use for a particular row.

    See http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#inheritance-tableperclass for details.

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

Sidebar

Related Questions

The title is a bit confusing but here's what I'm after: I have a
Ok I know the title is a bit confusing but here is my problem:
Bit long title, comes down to this: <?php class error { public function error($errormsg
Sorry if the title sounds a bit vague. Stackoverflow posting newbie here. I have
The title is a bit blur here, I didn't find a way to say
The title may be a bit vague, but here's my goal: I have a
The title may be bit confusing but here is what I am facing I
Ok, the title is a bit confusing, but here's my predicament. I've made a
Title might be a bit confusing, so let me explain. I have a website
The title is a bit difficult to put together for this question. Say I

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.