以下问题让我感到困惑。我想从关系中删除测量值,并且引用的对象应该更新测量值。那么我的问题是什么,如果我删除一个测量,哪个工作正常,但如果我从固化对象获得所有测量,我看到删除对象在里面。刷新关系的最佳方法是什么?
Measurement.java
@Entity
@Table(name = "measurements")
public class Measurement extends Model {
@Id
public Long id;
@Formats.DateTime(pattern = "dd.MM.yyyy")
public Date created = new Date();
@Constraints.Required
public double weight;
@Constraints.Required
public double belly;
@Constraints.Required
public double thigh;
@Constraints.Required
public double gluteal;
@ManyToOne
@JsonBackReference
public Cure cure;
}
Cure.java
@Entity
@Table(name = "cures")
public class Cure extends Model implements Comparable<Cure> {
@Id
public Long id;
@Formats.DateTime(pattern = "dd.MM.yyyy")
public Date created = new Date();
public int startHour = 10;
@ManyToOne
@JsonIgnore
public Challenge challenge;
@JsonManagedReference
@OneToMany
public List<Measurement> measurements;
}
应该处理删除的行动
public static Result delete(Long id){
Measurement measurement = Measurement.find.byId(id);
if(measurement == null && !measurement.belongsToUser(user)){
return noContent();
}
measurement.delete();
return ok();
}
答案 0 :(得分:0)
嗯,我没有在你的模特课上看到发现者。实施以下
public static Finder<Long, Measurement> find = new Finder<Long, Measurement>(Long.class, Measurement.class);
然后试试。此外,ebean有很多问题你可以使用原始查询删除,如下所示
SqlUpdate deletObject = Ebean
.createSqlUpdate("delete from table_name where id = "
+ id);
deletObject.execute();