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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:29:24+00:00 2026-05-22T03:29:24+00:00

So I have an interesting situation. I’ve inherited a big mess of code where

  • 0

So I have an interesting situation. I’ve inherited a big mess of code where the original developer decided to forego using inheritance in favor of enums and switch statements…it’s a perfect example of this anti-pattern Now it’s time to refactor, and I’ve decided the best way to go about it is to pull out a superclass backed by a table with shared columns and then use the joined subclass inheritance strategy. So far so good…

Now the tricky part is that this code has already been deployed to a production system. Accordingly, my refactored code has to be backwards-compatible with the schema/data out there, and I can’t start dropping redundant columns off of the subclass tables until one release in the future. Like it or not, I’m going to have duplicated columns between the parent and child tables for one release cycle.

Luckily for me, hibernate doesn’t flip out when it sees that there are duplicate columns between parent and child tables. But the bad news is that it doesn’t update said duplicated columns in both tables. The column in the parent table gets updated, but the one in the child is left stale.

For backward-compatibility with the current code, I’d like for the column to be updated in both tables. That way, updates to the entities aren’t lost if we have to rollback the release and go back to the old schema. While I know that I could take care of this via triggers, I’m looking for a code-only solution because triggers have a nasty habit of flying under the radar.

Is there anyone out there who can tell me a way to convince hibernate to hit both columns?

A very contrived example of my classes is:

@Entity
@Table(name = "superclass")
@Inheritance(strategy = InheritanceType.JOINED)
public class SuperClass {

    @Id @Generated
    Long id;
    boolean duplicate;
}

@Entity
@Table(name = "subclass")
public class SubClass extends SuperClass {
    String otherProperty;
}

With the tables to match:

CREATE TABLE superclass (
    id INT PRIMARY KEY AUTO_INCREMENT,
    duplicate BOOLEAN
);

CREATE TABLE subclass (
    id INT NOT NULL,
    duplicate BOOLEAN,
    otherProperty VARCHAR(255),
    FOREIGN KEY (id) REFERENCES superclass(id)
);

When inserting a new SubClass entity, the duplicate column on the subclass table will be NULL.

Thanks a bunch!

  • 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-22T03:29:25+00:00Added an answer on May 22, 2026 at 3:29 am

    How about defining two properties in your code, mapping one to each column, then keeping them in sync in the code? One is the real property, and one is a sort of shadow property. It’s not pretty, but it should be confined to the implementation of one class (or one class and its superclass).

    When you are able to drop the column, you can remove the shadow property.

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

Sidebar

Related Questions

I have an interesting situation. In some (large) legacy code, there is a namespace
Interesting situation. I have a section of code that creates several ZipOutputStreams. As a
I have faced some interesting situation. I have the following code to populate value
I have an interesting situation that EMF forced me into: abstract class AbstractDog{ ...
I have an interesting question on initialization. I have the following code: public class
I have an interesting situation, well it's probably not that unique at all, but
I have an interesting situation here this time. This more of a conceptual question,
I just found an interesting situation. Suppose you have some SwingWorker (I've made this
Have an interesting situation. Working with umbraco website and debugging it inside Visual Studio.
I'm working with vector now and I have an interesting situation which I need

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.