title: Insert data to multiple tables in spring jpa
body: <p>I have two tables, <strong>user</strong> and <strong>transaction</strong>. Where <code>one user</code> can have <code>many transactions</code>. So, everytime I <code>create new user</code>, they automatically make <code>new transaction</code> and the <code>transaction type</code> is <strong>SEND MONEY</strong>. But I don't understand how to write it in Spring JPA. Please take a look on my code and help me.</p>
  <p>User.java</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>@Entity
  @Table(name = "user")
  public class User {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "id")
      private long id;
  
      @Column(name = "name")
      private String name;
  
      @Column(name = "email")
      private String email;
  
      @Column(name = "password")
      private String password;
  
      @Column(name = "money")
      private int money;
      
      //Getter Setter Constructor
  }</code></pre>
  </div>
  </div>
  </p>
  <p>Transaction.java</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>@Entity
  @Table(name = "transaction")
  public class Transaction {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "id_trans")
      private long id_trans;
  
      @Column(name = "id_user")
      private long id_user;
  
      @Column(name = "transaction_date")
      private Timestamp transaction_date;
  
      @Column(name = "type") //Default set as "SEND MONEY"
      private String type;
  
      @Column(name = "trans_money") //From money in User.class
      private int trans_money;
  
  
      //Getter Setter Constructor
  }</code></pre>
  </div>
  </div>
  </p>
  <p>I know I should do something in my <strong>UserDAO.java</strong>, but I still don't know how to send data from body and split(?) it into two object (<code>user</code> and <code>transaction</code>, so I can persist it in <strong>UserDAO</strong>).</p>