title: how to save foreign key entities using spring DAO
body: <pre><code>    public class Customer implements Serializable {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "idCustomer")
      private Integer idCustomer;
  
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "idCustomer")
      private Collection&lt;Login&gt; loginCollection;
  
      }
  
      public class Login implements Serializable {
  
      private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Basic(optional = false)
      @Column(name = "idLogin")
  
      @JoinColumn(name = "idCustomer", referencedColumnName = "idCustomer")
      @ManyToOne(optional = false)
      private Customer idCustomer;
  
      }
  
      //trying to save the customer and login in the database  
  
          ArrayList&lt;Login&gt; logins = new ArrayList&lt;Login&gt;();
          Login log = new Login();
          log.setIdCustomer(cust);
          logins.add(log);
          cust.setLoginCollection(logins);
          cust = custRepo.save(cust);  //failed 
  
      //Login log = new Login();
      //log.setUName(user);
      //log.setPassword(pass);
      //log.setIdCustomer(cust);
      //cust = custRepo.save(cust);
      //logRepository.save(log);  //failed too.
  </code></pre>
  
  <p>I'm using spring data in my project. I have 2 model classes <code>Customer</code> and <code>Login</code>. My login class has a foreign key <code>idCustomer</code> in the database. When I try to save the customer without a login, it works fine but the problem is that I can't save a login object in the database. </p>
  
  <p>I'm getting an error saying </p>
  
  <blockquote>
    <p>Unknown column 'id_customer' in 'field list'
    the jpa entities are generated.</p>
  </blockquote>
  
  <p>Here is an image actual database.</p>
  
  <p><a href="https://i.stack.imgur.com/0Km2s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0Km2s.png" alt="enter image description here"></a></p>