title: With Hibernate joined-subclasses, is it possible to duplicate columns in super and sub-tables *and* keep them in sync?
body: <p>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 <a href="http://c2.com/cgi/wiki?SwitchStatementsSmell" rel="nofollow">this anti-pattern</a>  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...</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>Is there anyone out there who can tell me a way to convince hibernate to hit both columns?</p>
  
  <p>A very contrived example of my classes is:</p>
  
  <pre><code>@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;
  }
  </code></pre>
  
  <p>With the tables to match:</p>
  
  <pre><code>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)
  );
  </code></pre>
  
  <p>When inserting a new SubClass entity, the duplicate column on the subclass table will be NULL.</p>
  
  <p>Thanks a bunch!</p>