Java Ebean模型通过@onetomany关系获取客户信息和身份,而不承担债务
我是新的游戏框架,并试图使一个项目。也许有些部分我会出错,如果是的话请纠正我。我有3个模型,分别是客户、身份和债务。客户只有一个身份,有许多债务。虽然我试图只获取客户及其身份,但未来的结果包括其债务。我的错在哪里?在我的模型中,还是我在寻找错误的方法 Customers.javaJava Ebean模型通过@onetomany关系获取客户信息和身份,而不承担债务,java,playframework,playframework-2.0,ebean,Java,Playframework,Playframework 2.0,Ebean,我是新的游戏框架,并试图使一个项目。也许有些部分我会出错,如果是的话请纠正我。我有3个模型,分别是客户、身份和债务。客户只有一个身份,有许多债务。虽然我试图只获取客户及其身份,但未来的结果包括其债务。我的错在哪里?在我的模型中,还是我在寻找错误的方法 Customers.java @Entity @Table(name="customers") public class Customers extends Model { @Id @GeneratedValue(strategy = Gener
@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);
}
它是否包括仅填充了debt.id的
债务
?或者它是在查询完整的债务对象?它是在查询我不想看到的完整债务对象。我不确定它是否会工作,或者它是否是正确的解决方案,但您可以尝试添加:fetch=FetchType.LAZY
创建一个示例项目并将其放在github上需要大量的工作吗?我不能帮你自己复制它,如果我能帮忙的话当然:-)还有:你能删除吗?选择(“*”
,保留延迟提取,然后再试一次
@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);
}
@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);
}
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));
}
}