我有一个应该是多对多(双向)的列表
这是过滤器类:
@ManyToMany(targetEntity=Serving.class)
@JoinTable(name = "BRIDGE_SERV_FILTER", joinColumns={
@JoinColumn(name="filter_id")}, inverseJoinColumns={@JoinColumn(name="serving_id")})
private List<Serving> servings;
public List<Serving> getServing() { return this.servings; }
public void setServing(List<Serving> servings) { this.servings = servings; }
这是服务类:
@ManyToMany(targetEntity=Filter.class)
@JoinTable(name = "BRIDGE_SERV_FILTER", joinColumns={
@JoinColumn(name="serving_id")}, inverseJoinColumns={@JoinColumn(name="filter_id")})
private List<Filter> filters;
public List<Filter> getFilters() { return filters;}
public void setFilters(List<Filter> filters) { this.filters = filters;}
然后我应该调用一些东西来从服务中获取所有过滤器,这就是我所做的(服务是服务类型):
List<Filter> filters = serv.getFilters();
//iterate from all filter
for(Filter allf : allFilter)
{
boolean mark_this = false;
//..and matched the currently-iterated-all-filters with filter from
//which the serving got
for(com.pos.model.Filter f : filters)
{
//if matched, mark this current filter
if (allf.getId().equals(f.getId()))
mark_this = true;
}
tmodel.addRow(new Object[] { allf.getName(), mark_this });
}
该方法在模型中定义,并且是静态的。因此,当表单加载时,它会调用 jTable.setTableModel(Filter.toTableModel(thisServing));
它读取并显示数据。然而,Hibernate 也调用了 delete:
Hibernate: select filter0_.filter_id as filter1_2_, filter0_.is_showable as is2_2_, filter0_.name as name2_ from DIM_FILTER filter0_ where is_showable=true
Hibernate: select filters0_.serving_id as serving1_4_1_, filters0_.filter_id as filter2_6_1_, filter1_.filter_id as filter1_2_0_, filter1_.is_showable as is2_2_0_, filter1_.name as name2_0_ from BRIDGE_SERV_FILTER filters0_ inner join DIM_FILTER filter1_ on filters0_.filter_id=filter1_.filter_id where filters0_.serving_id=?
Hibernate: delete from BRIDGE_SERV_FILTER where serving_id=?
事实上,我根本不做任何删除,也不要求hibernate删除任何东西。可能会发生我不明白的事情......如何防止Hibernate被删除?还是我做错了什么?