【发布时间】:2011-09-03 05:42:28
【问题描述】:
考虑:
@Entity
public class M {
@ManyToMany
private List<E> es = new ArrayList<E>();
private E newE;
public M(E newE) {
this.newE = newE;
es.add(newE);
}
我不能assert(m.newE == m.getEs(0))吗?
只有在重新启动应用程序/PU 后我才能:
public List<E> getEs() {
final int indexOf = es.indexOf(newE);
if (indexOf != 0) {
es.remove(indexOf);
es.add(0, newE);
}
return Collections.unmodifiableList(es);
}
但是,这种繁重的代码甚至效率低下,因为它强制在实际需要之前从 PU 中加载 E 实体。有什么可行的替代方案吗?
【问题讨论】:
标签: jpa jpa-2.0 eclipselink