title: Java state pattern with different properties and sql
body: <p>I have main domain class <strong>Broadcast</strong> that can have <strong>three states</strong>:</p>
  <pre><code>public class Broadcast {
      private Long id;
      private String title;
      private Author author;
      private State state;
  
      // constructor, getters and setters                                                     
  }
  </code></pre>
  <p>Each state contains different properties.</p>
  <pre><code>public abstract class State {
      private Broadcast stateContext;
  
      public State(Broadcast stateContext) {
          this.stateContext = stateContext;
      }
  }
  
  public class UpcomingState extends State {
      private OffsetDateTime createdAt;
      private OffsetDateTime scheduledAt;
  
      public UpcomingState(Broadcast stateContext) {
          super(stateContext);
      }
  
      // getters and setters
  }
  
  public class LiveState extends State {
      private OffsetDateTime startedAt;
  
      public LiveState(Broadcast stateContext) {
          super(stateContext);
      }
  
      // getters and setters
  }
  
  public class EndedState extends State {
      private OffsetDateTime startedAt;
      private OffsetDateTime endedAt;
  
      public EndedState(Broadcast stateContext) {
          super(stateContext);
      }
  
      // getters and setters
  }
  </code></pre>
  <p>How do I design the tables in the database to store objects of this class (for example, postgresql) while still preserving information about state transitions, assuming some states might be applied multiple times?</p>
  <p>For example, upcoming -&gt; <strong>live (first data)</strong> -&gt; <strong>live (second data)</strong> -&gt; ended.</p>