有没有人知道如何从OneToMany-realtionship中获取arrayList? 目前我得到了一个持久性包,其特性/属性对我的应用程序起反作用。
请考虑以下代码:
@Entity
@Table(name = "FOOS")
@NamedQuery(name = "Foo.findAll", query = "SELECT r FROM Foo r")
public class Foo implements Serializable, IKontingent {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "foo", cascade = CascadeType.ALL)
private List<Ba> baList;
@Transient
private boolean editable;
public boolean isEditable() {
boolean editMode = true;
if (this.getBaList() == null || this.getBaList().size() == 0) {
editMode = false;
}
return editMode;
}
和
@Entity
@Table(name = "BAS")
@NamedQuery(name = "Ba.findAll", query = "SELECT o FROM Ba o")
public class Ba implements Serializable, IKontingentWithParent {
/**
* Generated
*/
private static final long serialVersionUID = 1856655370465252150L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "ba", cascade = CascadeType.ALL)
private List<MoreStuff> moreStuffList;
@NotNull
@ManyToOne
private Foo foo;
@Transient
private long temporalLong;
public long getTemporalLong() {
long sum = CollectionUtils.isEmpty(moreStuffList) == true ? 0L : this.getMoreStuffList().stream().collect(Collectors.summingLong(q -> q.getTemporalLong()));
return sum;
}
由于持久性包,我无法获得正确的temporalLong,因为它解析为0L。