类Car
与 1:n 关系Feature
:
@OneToMany(mappedBy="car", fetch = FetchType.EAGER)
private List<Feature> features;
Class 中的表示形式Feature
如下所示:
@ManyToOne(fetch = FetchType.EAGER)
private Car car;
当我将Feature
与某个Car
-Object 关联的一个 -object 传递给DatabaseService#delete()
它时,它将成功地从数据库中删除,但仍位于Car
-Objects 功能列表中。
package mypackage;
import java.io.Serializable;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Stateless
public class DatabaseService implements Serializable {
@PersistenceContext
private EntityManager em;
public void delete(Object o) {
o = em.merge(o);
em.remove(o);
}
}