public class Customer implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "idCustomer")
private Integer idCustomer;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "idCustomer")
private Collection<Login> 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<Login> logins = new ArrayList<Login>();
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.
I'm using spring data in my project. I have 2 model classes Customer
and Login
. My login class has a foreign key idCustomer
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.
I'm getting an error saying
Unknown column 'id_customer' in 'field list' the jpa entities are generated.
Here is an image actual database.