Course实体类中有论坛集合:
@OneToMany(fetch=FetchType.LAZY,cascade=CascadeType.REMOVE)
private List<Forum> forumList=new ArrayList<Forum>();Forum实体类中有帖子集合:
@OneToMany(fetch=FetchType.LAZY,cascade=CascadeType.REMOVE)
private List<Post> postList=new ArrayList<Post>();现在想要删除某课程下的所有帖子,下面两种方法那种是正确的:
方法一:
for(Forum forum:course.getForumList())
{
     for(Post post:forum.getPostList())
    {
         em.remove(post);
     }
}
方法二:
query=em.createQuery("select c.forumList from Course c where c.id=?1");
query.setParameter(1, course.getCourseId());
List<Forum> forumList=(List<Forum>)query.getResultList();
for(Forum forum:forumList)
{
Query q=em.createQuery("select f.postList from Forum f where forum.id=?1");
q.setParameter(1, forum.getForumId());
for(Post post:(List<Post>)q.getResultList())
{
    em.remove(post);
}
}
不要关注一下语法上的小细节了。问那种方法是正确的?!!急!