I have two model classes
CustomerAccount
@Entity
public class CustomerAccount extends Model {
@Id
@Column(columnDefinition = "int(11)")
public int customer_id;
@Column(columnDefinition = "varchar(50) not null unique")
public String customer_email;
@Column(columnDefinition = "varchar(50) not null")
public String password;
}
Customer
@Entity
public class Customer extends Model {
@Column(columnDefinition = "int(11) unique")
public int customer_id = 6;
@Column(columnDefinition = "varchar(50) not null")
public String customer_fname;
@Column(columnDefinition = "varchar(50) not null")
public String customer_lname;
@Column(columnDefinition = "varchar(50) unique not null")
public String email = "";
}
Now I want to add a foriegn key in table CustomerAccount reference to Customer table like: -
Foreign Key (customer_email) references Customer(email);
Please tell me how to do this...
while running the following code to add details to Customer Account
public static Result addPerson() {
String result = "ok";
CustomerAccount Customer_Account = Form.form(CustomerAccount.class).bindFromRequest().get();
List<CustomerAccount> personsDetails = new Model.Finder(String.class, CustomerAccount.class).all();
for (CustomerAccount product : personsDetails) {
if (product.customer.email.equals(Customer_Account.customer.email) ) {
result = "";
}
}
if (result.equals("ok")) {
Customer_Account.save();
return ok("New Customer Account Created");
}else{
return ok("Customer with same email Already Exists");
}
}
I am getting this error
[PersistenceException: ERROR executing DML bindLog[] error[Column 'customer_email' cannot be null]]