【发布时间】:2015-05-13 11:37:01
【问题描述】:
我有两个模型类
客户帐户
@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;
}
客户
@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 = "";
}
现在我想在 CustomerAccount 表中添加一个外键来引用 Customer 表,例如:-
外键(customer_email)引用客户(email);
请告诉我该怎么做...
在运行以下代码向客户帐户添加详细信息时
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");
}
}
我收到了这个错误
[PersistenceException: ERROR executing DML bindLog[] error[Column 'customer_email' cannot be null]]
【问题讨论】:
-
您是否尝试过文档中使用的任何注释:playframework.com/documentation/1.2.x/cheatsheet/model。如果是这样,最好明确说明它们对你没有用的地方。
-
我很困惑如何实现这一点。我已经开始学习 Play。
标签: playframework foreign-key-relationship ebean