title: how to save multiple tables using Spring boot JpaRepository
body: <p>I have Two Tables Those are User and UserDetails. </p>
  
  <pre><code>@Entity
  public class User {
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Integer id;
  
  private String userName;
  
  private String password;
  
  }
  
  
  @Entity
  public class UserDetails {
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Integer id;
  
  private String firstName;
  
  private String lastName;
  
  private String address;
  
  private Date birthday;
  
  @ManyToOne
  private User user;
  
  }
  </code></pre>
  
  <p>there is not show getters and setter.</p>
  
  <p>I am using spring boot for creating my application. when I go to save <code>User</code>, I want to save those two tables in same time. It means first save <code>User</code> table and then I  save <code>UserDetails</code> table (to save <code>UserDetails</code> table, <code>User</code> table primary key is required). how I do this thing using spring boot JPA repository? Another thing, in case <code>UserDetails</code> table is not saved, we want to roll-back our whole transaction (it means we have to rollback user table).</p>
  
  <p>this is my services class</p>
  
  <pre><code>@Service
  @Transactional
  public class UserDetailsService {
      @Autowired
      private UserDetailsRepository userDetailsRepository;
      @Autowired
      private UserRepository userRepository;
      void saveUserDetails(String userName, String password, String firstName, String lastName,
              String address, Date birthday) {
          User n = new User();
          n.setUserName(userName);
          n.setPassword(password);
          UserDetails ud = new UserDetails();
          ud.setFirstName(firstName);
          ud.setlastName(lastName);
          ud.setAddress(address);
          ud.setBirthDate(birthday);
          userRepository.save(n);
          userDetailsRepository.save(ud);
      }
  }
  </code></pre>