我是Play框架的新手并尝试制作一个项目。也许某些部分我会出错,如果有的话请纠正我。我有3个模型,分别是客户,身份和债务。客户有一个身份,有很多债务。虽然我试图只获得客户及其身份,但未来的结果包括其债务。我的错误在哪里?在我的模特中,我正在寻找错误的方式?
Customers.java
@Entity
@Table(name="customers")
public class Customers extends Model {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public int id;
public int identity_id;
@Formats.DateTime(pattern = "dd/MM/yy")
public Date register_date;
public boolean status;
public Date closing_date;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy HH:mm:ss")
public Date created_at;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy HH:mm:ss")
public Date updated_at;
@OneToOne
@JoinColumn(name="identity_id", referencedColumnName = "id", unique = true)
public Identities identity;
@OneToMany(mappedBy = "customer", cascade=CascadeType.ALL)
public List<Debts> debts;
public static final Finder<Long, Customers> find = new Finder<>(
Long.class, Customers.class);
}
Identities.java
@Entity
@Table(name="identities")
public class Identities extends Model {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public int id;
@Constraints.Required
public int customer_id;
public Long citizen_no;
public String full_name;
@JsonSerialize(using = JsonDateSerializer.class)
public Date birthdate;
public Integer place_of_birth;
public String father_name;
public String mother_name;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy HH:mm:ss")
public Date created_at;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy HH:mm:ss")
public Date updated_at;
public static final Model.Finder<Long, Identities> find = new Model.Finder<>(
Long.class, Identities.class);
}
Debts.java
@Entity
@Table(name="debts")
public class Debts extends Model {
@Id
public Long id;
public int customer_id;
public Integer payment_id;
@JsonSerialize(using = JsonDateSerializer.class)
public Date billed_date;
public Float cost;
public Float taxes;
public boolean status;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy HH:mm:ss")
public Date created_at;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy HH:mm:ss")
public Date updated_at;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "customer_id", referencedColumnName = "id")
private Customers customer;
public static final Model.Finder<Long, Debts> find = new Model.Finder<>(
Long.class, Debts.class);
}
CustomerController.java
public class CustomersController extends BaseController {
public Result show(long id) {
Customers customer = Customers.find.select("*")
.fetch("identity")
.where()
.eq("id", id)
.findUnique();
return ok(Json.toJson(customer));
}
}