title: Data Migration between two tables with different schema for Java EE application
body: <p>I want to migrate the data from one table to another, besides the two tables with different table name they also have different schema.</p>
  
  <p>For example, existing table are:</p>
  
  <pre><code>@Entity
  public class Address {
       private String uuid;
       private String street;
       private String postcode;
  }
  
  @Entity
  public class User {
       private String uuid;
       private String name;
       @One2One
       private Address address;
  }
  </code></pre>
  
  <p>After the requirements changed, we refactor the two class to something like this:</p>
  
  <pre><code>@Entity
  public class UserChanged {
       private String uuid;
       private String name;
       @Embedded
       @AttributeOverrides(.....)
       private Address address;
  }
  @Embeddable 
  public class AddressChanged {
       private String street;
       private String postcode;
  }
  </code></pre>
  
  <p>Which means, in the new, we have only one table "UserChanged", we have all the columns contain the user information, like uuid, name, street, and postcode. However for the existing, we have two tables which are "User" and "Address", in the "User" table, there is a foreign key "address" which reference the table "Address" using the primary key.</p>
  
  <pre><code>Address
  ------------------
  uuid          varchar (primary key)
  street        varchar
  postcode      varchar
  
  
  User
  ------------------
  uuid          varchar (primary key)
  name          varchar
  address_id    varchar (foreign key)
  
  
  UserChanged
  ------------------
  uuid          varchar (primary key)
  name          varchar
  street        varchar
  postcode      varchar
  </code></pre>
  
  <p>So what I want to do is migrate all the data information in "User" and "Address" tables to just one table "UserChanged", i.e. User + Address -> UserChanged.</p>
  
  <p>Anyone can tell me the sql scripts I should write for this migration requirement.</p>